PYTHON Explain lines 20, 22, 24, and 28. Also, create line 26 and explain the so
ID: 3934443 • Letter: P
Question
PYTHON
Explain lines 20, 22, 24, and 28. Also, create line 26 and explain the solution.
Def (): # Declare local variables number = 5 number_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Display the number. Print ('Number:', number) # Display the list of numbers. Print ('List of numbers: ', number_list, sep = ' ') # Display the list of numbers that are larger # than the number. Print ('List of numbers that are larger than', number, ':', sep = ' ') # Call the display_larger_than_n_list function, # passing a number and number list as arguments. display_larger_than_n_list (number, number_list) # The display_larger_than_n_list (number, number_list) The display_larger_than_n_list function accepts two arguments: # a list, and a number. The function displays all of the numbers # in the list that are greater than the number. def display larger than n list (n, n list): # Declare an empty list. larger than n list = [] # Loop through the values in the list. for value in n list: # Determine if a value is greater than n. ?? ????? ? ?: # If so, append the value to the list. larger than n list. append (value) # Display the list. print (larger_than_n_list) # Call the main function. main ()Explanation / Answer
Line 20 defines a function display_larger_than_n_list function which takes 2 parameters n an integer number and a n_list of a list type.
Line 22 defines a variable larger_than_n_list which is initialized to an empty list.
line 24 defines a for loop which iterates over each item in the list n_list.
line 26 should be if the value in a list is greater than n than append it to larger_than_n_list.
if value>n:
line 28 appends the value in a list larger_than_n_list which greater than n
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.