python - Reading a list from file, then writing in a loop to solve for math equation -


i have list in file made of numbers.

i have command read number in list:

but having error:

typeerror: 'int' object not subscriptable 

which don't understand 'int' issue.

with open('angles.txt', 'r') f:     print('angle sine         cosine      tangent')      number in f:         degree= int(number)         rad = math.radians(degree)         sin = math.sin(rad)          answer = degree[0]         print(str(answer), end = '')          print(format(math.sin(math.radians(rad)),'10.5f'),end='')         print(format(math.cos(math.radians(rad)),'10.5f'),end='')         print(format(math.tan(math.radians(rad)),'10.5f'),end='') 

i can answer specific question int type error. problem these 2 lines don't make sense python:

degree = int(number)  answer = degree[0] 

you're first defining degree integer, , trying access integer list! doesn't work.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -