I am working on learning recursion and have written this bit of code to return the sum of all numbers from one up to the chosen number. When I run the program, no matter what number I initially enter, the sum it gives me is always "None", and by that I mean, the value of the outputSum variable seems to be "None" in my program. I thought changing the initialized value of SUM_OF_NUMBERS might change this, but it didn't, I still got "None" as the output. Can anyone point to the part in my code that is causing this bug?
def sumOfNumbers(number):
SUM_OF_NUMBERS = 0
if number > 0:
SUM_OF_NUMBERS = SUM_OF_NUMBERS + number
else:
return SUM_OF_NUMBERS
number = number - 1
sumOfNumbers(number)
def main():
repeat = 'Y'
outputSum = 0
while repeat == 'Y' or repeat == 'y':
print("Welcome to the Sum Of Numbers program!")
number = int(input("\nPlease enter a number to sum up: "))
outputSum = sumOfNumbers(number)
print("\nThe sum of all numbers from 1 to " + str(number) + \
" is " + str(outputSum))
repeat = input("\nWould you like to sum up another number?" \
'\nEnter "Y" for "YES" or "N" for "NO": ')
if repeat == 'N' or repeat == 'n':
print("\nThank you for using the program.")
else:
print("\nSorry, that was not a valid option.")
repeat = input('Please enter "Y" for "YES" or "N" for "NO": ')
main()