c0ffi c0ffi - 9 months ago 31
Python Question

How to get floats out of list one by one to calculate with them

I have list with float values, but I need to use them 1 by 1 and do some stuff with them. I want to use them, but I don't know how to get them out of list one by one.

listthing = [7.0, 3.9, 5.25]


Now I need to use them in calculation

lenghtstuff = float(listthing) * 100 * (7.0 * 2.0 + 0.5)


But I need to make calculation with each value from the list , and don't know how to do it so it would do
1) 7.0 * 100 * (7.0 * 2.0 + 0.5)

2) 3.9 * 100 * (7.0 * 2.0 + 0.5) etc

Sty Sty
Answer Source

Use a for loop.

for number in listthing:
    lenghtstuff = float(number) * 100 * (7.0 * 2.0 + 0.5)
    #do something with lengthstuff such as print it or append it to another list