Ask Question

Write a Python program that uses a loop to calculate the total of a series of fractions as below. Inside the loop should be the two statements to (a) divide the numerator by the denominator and (b) add the result to a total. Display the total after the loop. Notice that the numerator increases by 1 after each iteration and the denominator decreases by 1. The lower and upper values in both cases are 1 and 30.

+2
Answers (1)
  1. 2 October, 00:13
    0
    numeratorValue = 1

    denominatorValue = 30

    count = 0

    while numeratorValue < = 30:

    difference = numeratorValue / denominatorValue

    count + = difference

    numeratorValue + = 1

    denominatorValue - = 1

    print (count)

    Explanation:

    Initialize the required variables and run a while loop until the numeratorValue is less than 30. Inside the while loop, calculate the difference by dividing the numeratorValue by denominatorValue. Add the value of difference variable to the count. Increment both the numeratorValue and denominatorValue. Lastly display the value of count.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a Python program that uses a loop to calculate the total of a series of fractions as below. Inside the loop should be the two ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers