Computer Science, asked by eshanthkatakam, 6 months ago

Write a program in python to print the sum of all even and odd numbers in a range

Answers

Answered by parvathi66
31

Answer:

maximum = int(input(" Please Enter the Maximum Value : "))

even_total = 0

odd_total = 0

for number in range(1, maximum + 1):

if(number % 2 == 0):

even_total = even_total + number

else:

odd_total = odd_total + number

print("The Sum of Even Numbers from 1 to {0} = {1}".format(number, even_total))

print("The Sum of Odd Numbers from 1 to {0} = {1}".format(number, odd_total))

Explanation:

Is this correct

Answered by snowghost144
2

Answer:

maximum = int(input(" Please Enter the Maximum Value : "))

even_total = 0

odd_total = 0

for number in range(1, maximum + 1):

if(number % 2 == 0):

even_total = even_total + number

else:

odd_total = odd_total + number

print("The Sum of Even Numbers from 1 to {0} = {1}".format(number, even_total))

print("The Sum of Odd Numbers from 1 to {0} = {1}".format(number, odd_total))

Explanation:

you could replace the odd to even by the str nd thn print it by the input thn u could do it

Similar questions