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])
i=i+1
print q

Thanks for explaining!
Alopax
 
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
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 764
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 3 guests