In a program, write a function that accepts two arguments: a list, and a number
ID: 3683729 • Letter: I
Question
In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n.
I am writing this program in Python and so far I have this:
#programming exercise 7-6
def main():
#declare local variables.
number = 10
num_list = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
#display the number
print('Number:', number)
#display the list of numbers.
print('List of numbers: ', num_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 a number list as arguments.
display_larger_than_n_list(number, num_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 value in the list.
for value in n_list:
#determine if a value is greater than n.
I cannot figure out the next line of code and I was hoping to get a solution to the problem with a detailed explanation. Thank you so much!!!
Explanation / Answer
def display_larger_than_n_list(n, n_list):
#declare an empty list.
larger_than_n_list = []
#loop through the value in the list.
for value in n_list:
#determine if a value is greater than n.
if value < nlist:
larger_than_n_list=nlist
return larger_than_n_list
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.