Display a list

This is the place for queries that don't fit in any of the other categories.

Display a list

Postby Alopax » Sun Mar 24, 2013 11:25 am

Hey all,

I'm really new to Python and even the simplest things are hard for me to understand. That being said, I've written a simple loop to find q based on some other variables taken from data, but it only displays the last q value computed. I want it to display the entire list, but all I've gotten in terms of "help" from my lab group says "make sure it's a list and then have it print." Isn't it already a list if it is computing multiple values? How do I modify it otherwise?

Here's the code:
for i in range(len(vf)):
a = math.sqrt((b/(2*p))**2 + 9*eta*vf[i]/(2*g*rho)) - b/(2*p)
m = 4/3 * math.pi * a**3 * rho
q = m * g * (vf[i]+vr[i])/ (E * vf[i])
print q

Thanks for explaining!
Posts: 1
Joined: Sun Mar 24, 2013 11:22 am

Re: Display a list

Postby Yoriz » Sun Mar 24, 2013 12:15 pm

Hi welcome to the forum

Please read this post on how to post your code

The code you posted will not run, its should be in code tags so it has lost its indentation, imports missing and you have variables which are not defined.

If you don't store multiple values in a list you just over write the value in a variable each time you loop so your variable q needs to be a list, you can learn about them here

It would probably be a good idea for you to go through the python tutorial
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests