I'm new to python and I started learning to execute function. And I started adding numbers but I could only sum two numbers and if I wanted to sum more, it would require I edit the program. Here's my code
def sum(num1,num2):
return num1+num2
a=5
b=7
c=sum(a,b)
print (c)
Now I want to create a function to sum any amount of number you want without Editting the codes. Here was what I did:
def sum(num1,num2):
return num1+num2
a=int(input("what is the number you want to add?: "))
ask="yes"
while(ask=="yes"):
b=int(input("what is the number you want to add?: "))
c=sum(a,b)
a=c
ask=input("do you want to add another number?: ")
else:
c=a
print (c)
This worked but i think there should be an easier way to do this with a function... right? Thanks for your help!