How do I add five numbers from user input in Python?

前端 未结 5 1731
时光说笑
时光说笑 2021-01-16 08:49

As a practice exercise, I am trying to get five numbers from a user and return the sum of all five number using a while loop. I managed to gather the five numbers, but the

5条回答
  •  梦谈多话
    2021-01-16 09:23

    This should be better.

    x = 0
    s = 0   
    while x < 5:
        x += 1
        s += (int(raw_input("Enter a number: ")))
    print s
    

    You were putting one of the results on to the sum of all results and lost the previous ones.

提交回复
热议问题