Quiz Python 5. Loops

Don't have a Resume?




Question :

Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100?

A:
sum = 0
for i in range(1, 99):
    sum += i / (i + 1)

print("Sum is", sum)

B:
sum = 0
for i in range(1, 100):
    sum += i / (i + 1)

print("Sum is", sum)

C:
sum = 0
for i in range(1.0, 99.0):
    sum += i / (i + 1)

print("Sum is", sum)

D:
sum = 0
for i in range(1.0, 100.0):
    sum += i / (i + 1)

print("Sum is", sum)

  1. BCD
  2. ABCD
  3. B
  4. CDE
Answer : Option 3