Create a function that expects no arguments. The function asks user to enter a series of numbers greater than or equal to zero, one at a time. The user types end to indicate that there are no more numbers. The function computes the sum of all the values entered.
I'm supposed to be able to do this with just while loops and if statements.
The main issue I'm running into is that I don't know how to make it so that "end" actually stops the loop, rather than add to the value.
def SumFunction():
"""Sum of all values entered"""
number = 0
while number >= 0 and number is not "end":
number = number + (float(input("Enter next number: ")))
return number
Aucun commentaire:
Enregistrer un commentaire