Q:

Write python program that takes two numbers from the user( low and high ) and calculates the average of all odd numbers between the low and high numbers, and prints both the sum and average of these odd numbers using loop

0

Write a python program that takes two numbers from the user( low and high ) and calculates the average of all odd numbers between the low and high numbers, 

and prints both the sum and average of these odd numbers using loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using for loop:

low=int(input('enter first number (low): '))
high=int(input('enter second number (high): '))

sum_odd_numbers=0
average_odd_numbers=0
counter_odd_numbers=0
for i in range(low+1,high):
    if i%2!=0:
        sum_odd_numbers=sum_odd_numbers+i
        counter_odd_numbers=counter_odd_numbers+1
average_odd_numbers=sum_odd_numbers/counter_odd_numbers
print('total odd numbers are: ',sum_odd_numbers)
print('average odd numbers are: ',average_odd_numbers)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now