Skip to content

Commit 9895c35

Browse files
authored
Merge pull request #105 from amirmohammadre/issue98
resolving issue98
2 parents 58a1524 + 71b41da commit 9895c35

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sum_odd_numbers.py

Lines changed: 20 additions & 0 deletions
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)