Skip to content

Commit 71b41da

Browse files
author
amir mohammad
committed
resolving issue98
1 parent 58a1524 commit 71b41da

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sum_odd_numbers.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Find the sum of all odd numbers in a given range
3+
"""
4+
5+
try:
6+
max = int(input("Enter the maximum value: "))
7+
Oddsum = 0
8+
9+
except Exception as error:
10+
print("An error has occurred! => ", str(error))
11+
exit()
12+
13+
else:
14+
for num in range(1, max + 1):
15+
if num % 2 != 0:
16+
print("{0}".format(num))
17+
Oddsum += num
18+
19+
print("The sum of odd numbers from 1 to {0} = {1}".format(num, Oddsum))
20+

0 commit comments

Comments
 (0)