CBSE Class 11 Computer Science
Question 101 of 104
List Manipulation — Question 15
Back to all questions 15
Question Question 12
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.
Solution
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