FIX THE PROGRAM BELOW. #Function to get the key value ind dictionary def get_key(val): for key, value in result.items(): if val == value: return key return "key doesn't exist" #Function definition to find the tallest height def tall(list_height): return max(list_height) #Function to find the shortest height def short(list_height): return min(list_height) # creating an empty list list_names list_names = [] # Get the number of baby names as input from user num1 = int(input("Enter number of baby names : ")) # iterating till the range for i in range(0, num1): name = input() list_names.append(name) # adding the element print("list of baby names : ",list_names) # creating an empty list list_height list_height = [] # iterating till the range for i in range(0, num1): height = int(input()) list_height.append(height) # adding the element print("list of baby heights : ", list_height) # using dictionary comprehension to convert lists to dictionary result = {list_names[i]: list_height[i] for i in range(len(list_names))} letter=input("Enter T to find tallest baby and S to find the shortest baby : ") #If the entered letetr is S, find the shortest baby if (letter=="S"): #call the function short(), to find the smallest height short=short(list_height) # printing the minimum height print("Minimum height : ", short) #call the function get_key(short) to find the baby name corersponding to the number print("Shortest baby is:", get_key(short)) #if the letter entered is elif (letter=="T"): tall=tall(list_height) # printing the maximum height print("Maximum height : ", tall) #call the function get_key(tall) to find the baby name corersponding to the number print("Tallest baby is:", get_key(tall)) else: print("Invalid letter")
FIX THE PROGRAM BELOW.
#Function to get the key value ind dictionary
def get_key(val):
for key, value in result.items():
if val == value:
return key
return "key doesn't exist"
#Function definition to find the tallest height
def tall(list_height):
return max(list_height)
#Function to find the shortest height
def short(list_height):
return min(list_height)
# creating an empty list list_names
list_names = []
# Get the number of baby names as input from user
num1 = int(input("Enter number of baby names : "))
# iterating till the range
for i in range(0, num1):
name = input()
list_names.append(name) # adding the element
print("list of baby names : ",list_names)
# creating an empty list list_height
list_height = []
# iterating till the range
for i in range(0, num1):
height = int(input())
list_height.append(height) # adding the element
print("list of baby heights : ", list_height)
# using dictionary comprehension to convert lists to dictionary
result = {list_names[i]: list_height[i] for i in range(len(list_names))}
letter=input("Enter T to find tallest baby and S to find the shortest baby : ")
#If the entered letetr is S, find the shortest baby
if (letter=="S"):
#call the function short(), to find the smallest height
short=short(list_height)
# printing the minimum height
print("Minimum height : ", short)
#call the function get_key(short) to find the baby name corersponding to the number
print("Shortest baby is:", get_key(short))
#if the letter entered is
elif (letter=="T"):
tall=tall(list_height)
# printing the maximum height
print("Maximum height : ", tall)
#call the function get_key(tall) to find the baby name corersponding to the number
print("Tallest baby is:", get_key(tall))
else:
print("Invalid letter")
The correct code is given below.
Sample Response:
#Function to get the key value ind dictionary
def get_key(val):
for key, value in result.items():
if val == value:
return key
return "key doesn't exist"
#Function definition to find the tallest height
def tall(list_height):
max=list_height[0]
for i in range(len(list_height)):
if max<list_height[i]:
max=list_height[i]
return max
#Function to find the shortest height
def short(list_height):
min=list_height[0]
for i in range(len(list_height)):
if min>list_height[i]:
min=list_height[i]
return min
# creating an empty list list_names
list_names = []
# Get the number of baby names as input from user
num1 = int(input("Enter number of baby names : "))
print("Please enter the baby names.")
# iterating till the range
for i in range(0, num1):
name = input()
list_names.append(name) # adding the element
print("list of baby names : ",list_names)
# creating an empty list list_height
list_height=[]
print("Please enter the baby heights.")
# iterating till the range
for i in range(0, num1):
height=int(input())
list_height.append(height) # adding the element
print("list of baby heights : ",list_height)
# using dictionary comprehension to convert lists to dictionary
result={list_names[i]: list_height[i] for i in range(len(list_names))}
letter=input("Enter T to find tallest baby and S to find the shortest baby : ")
#If the entered letter is S, find the shortest baby
if (letter=="S"):
#call the function short(), to find the smallest height
short=short(list_height)
# printing the minimum height
print("Minimum height : ",short)
#call the function get_key(short) to find the baby name corresponding to the number
print("Shortest baby is:",get_key(short))
#if the letter entered is
elif (letter=="T"):
tall=tall(list_height)
# printing the maximum height
print("Maximum height : ", tall)
#call the function get_key(tall) to find the baby name corersponding to the number
print("Tallest baby is:", get_key(tall))
else:
print("Invalid letter")
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images