-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathq06.py
33 lines (26 loc) · 800 Bytes
/
q06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# sum of numbers
def main():
# set beginning point
beg=1
# get the data from the user
end=int(input("Enter a positive integer: "))
print()
# call the function
total=sum_num(beg, end)
# display the result.
print("The total of the numbers from 1 up to", end, "equals to", total)
def sum_num(beg, end):
if beg<=end:
return beg + sum_num(beg+1, end)
else:
return 0
# alternative
#===========================================================================
# # or
# if beg<end:
# return beg + sum_num(beg+1, end)
# else:
# return beg
#===========================================================================
# call the main function
main()