KnowledgeBoat Logo

Computer Science

Write a program to read two lists num and denum which contain the numerators and denominators of same fractions at the respective indexes. Then display the smallest fraction along with its index.

Python

Python List Manipulation

34 Likes

Answer

num = eval(input("Enter numerators list: "))
denum = eval(input("Enter denominators list: "))

small = 0.0
smallIdx = 0

for i in range(len(num)):
    t = num[i] / denum[i]
    if t < small:
        small = t
        smallIdx = i

print("Smallest Fraction =", num[smallIdx], "/", denum[smallIdx])
print("Index of Smallest Fraction =", smallIdx)

Output

Enter numerators list: [1, 3, 1, 7, 3]
Enter denominators list: [2, 4, 4, 13, 8]
Smallest Fraction = 1 / 2
Index of Smallest Fraction = 0

Answered By

14 Likes


Related Questions