0

I have an input and then a loop that outputs 5 numbers I want to use in another function but I don't have any clue how to do this as I am a beginner.

    mass_of_rider_kg = float(input('input mass of rider in kilograms:'))
    a = mass_of_rider_kg
    while a < mass_of_rider_kg+16:
         a = a + 4
         print(a)

This gives me the numbers I want but I am unsure how to put each of them into another equation to get 5 results.

1
  • Are you trying to put each one, one at a time, into another equation, and print the results of evaluating the equation each time? Or put all 5 of them into an equation together? Commented Oct 4, 2013 at 1:44

2 Answers 2

3
def otherfunction(a):
    ...

...
mass_of_rider_kg = float(input('input mass of rider in kilograms:'))
a = mass_of_rider_kg
while a < mass_of_rider_kg+16:
     a = a + 4
     otherfunction(a)
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to use numbers, you have to store them somewhere. If you just print them out, they go to the screen and are immediately forgotten.

You've already got each value stored in a. If all you want to do is use each value, separately, in another equation, just use a:

while a < mass_of_rider_kg+16:
    a = a + 4
    print(a)
    eggs = a * 20
    print(eggs)

But if you want to use all of the a values, how do you do that? Each time through the loop, you lose the previous a when you get the new one.

To store all of them, you put them in a list, and then you can use the list after the loop is done. For example:

masses = []
while a < mass_of_rider_kg+16:
     a = a + 4
     print(a)
     masses.append(a)
total = sum(masses)
print(total)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.