129k views
1 vote
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.

1 Answer

1 vote

Answer:

numeratorValue = 1

denominatorValue = 30

count = 0

while numeratorValue <= 30:

difference = numeratorValue / denominatorValue

count += difference

numeratorValue += 1

denominatorValue -= 1

print(count)

Step-by-step 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.
User Ericcco
by
4.7k points