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.
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
Related Questions
Write programs as per following specifications:
'''Print the length of the longest
string in the list of strings str_list.
Precondition : the list will contain
at least one element.'''Write programs as per following specifications:
'''L is a list of numbers. Print a new list where each element is the corresponding element of list L summed with number num.'''
Write a program to display the maximum and minimum values from the specified range of indexes of list.
Write a program to move all duplicate values in a list to the end of the list.