Reputation: 149
This is an intro level coding course in python so PLEASE go easy on the terminology as we are just taking baby steps. Here is my for loop that I am trying to work.
g=9.81
h0=1
radians=pi*thetas(j)/180
distances=range(31)
hvals=range(31)
thetas=[5,10,15,20,25,35,45,55,65,75,85]
for j,k in enumerate(thetas):
print j,k
xvals=range(31)
xvals=[0.1*x for x in xvals]
for i,v in enumerate(xvals):
print i,v
for j=0 to k:
radians=pi*thetas(j)/180
print radians
Now what I am essentially trying to do here is have this for loop run through the values of the list "thetas" and then print them out in a list. Can someone help me out here a bit? Thanks!
Upvotes: 1
Views: 135
Reputation: 117971
Your idea is correct, but your syntax is wrong
for j=0 to k: # this isn't how you iterate over a range
radians=pi*thetas(j)/180 # need to use [] instead of () to index a list
print radians
The correct syntax for this would be
pi = 3.14
for j in range(len(thetas)):
radians=pi*thetas[j]/180.0
print radians
Or you can skip indexing all together
for angle in thetas:
radians = pi * angle / 180.0
print radians
Or you can do the whole thing in a list comprehension
radians = [pi * angle / 180.0 for angle in thetas]
Upvotes: 2