def sum_numbers(numbers): return sum(numbers) def nums(): numbers = [] print("Enter numbers to add them up. If you want to stop, type 'n'.") while True: user_input = input("Enter a number: ") if user_input.lower() == 'n': break try: numbers.append(float(user_input)) except ValueError: print("Invalid. Please enter a valid number.") total = sum_numbers(numbers) print("The total sum of the numbers you entered is:", str(total)) nums()
Enter numbers to add them up. If you want to stop, type 'n'. The total sum of the numbers you entered is: 209.0