From 9a4dfa1c490fe314be0a0f9ae10463bea71ba073 Mon Sep 17 00:00:00 2001 From: Soua Date: Tue, 22 Oct 2019 11:17:21 -0500 Subject: [PATCH] Answered 8th beginner python question --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 8c799c7..cbb6387 100644 --- a/README.md +++ b/README.md @@ -1852,6 +1852,20 @@ for char in 'pizza':
Write a function to return the sum of one or more numbers. The user will decide how many numbers to use.
+``` +First you ask the user for the amount of numbers that will be use. Use a while loop that runs until amount_of_numbers becomes 0 through subtracting amount_of_numbers by one each loop. In the while loop you want ask the user for a number which will be added a variable each time the loop runs. + +def returnsum(): + amount_of_numbers = int(input("How many numbers? ")) + total_sum = 0 + while amount_of_numbers != 0: + num = int(input("Input a number. ")) + total_sum += num + amount_of_numbers -= 1 + return total_sum + +``` +