In Python, In a program write a function that accepts two arguments: a list, an 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. Here is what I have so far.

#call the main function
def main:
#declares local variables
number = 5
number_list = [1,2,3,4,5,6,7,8,9,10]
#displays the number
print('Number', number)
#displays the list of numbers
print('List of numbers:/n', 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 larger_than_n_list function,
#passing a number and number list as arguments.
display_larger)than_n_list(number, number_list)
# The display_largger_than_n_list function acceps two arguments:
#a list, and a number. The function displays all of the numbers
#in the list that are greater than that 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 valie in n_list:
#Determins if a value is greatter than n.
dont know what goes here
#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()

Respuesta :

Answer:

#call the main function

def main():

   #declares local variables

   number = 5

   number_list = [1,2,3,4,5,6,7,8,9,10]

   #displays the number

   print('Number', number)

   #displays the list of numbers

   print('List of numbers:\n', 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 larger_than_n_list function,

   #passing a number and number list as arguments.

   display_larger_than_n_list(number, number_list)

   # The display_largger_than_n_list function acceps two arguments:

   #a list, and a number. The function displays all of the numbers

   #in the list that are greater than that 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 greatter than n.

       # dont know what goes here

       #if so, append the value to the list

       if (value > n):

           larger_than_n_list.append(value)

   #Display the list.

   print(larger_than_n_list)

#Call the main function

main()

Explanation:

The above is the corrected code and it works properly. Some of the errors noted and corrected include:

  • omission of bracket from of main. It should be main()
  • displaying larger_than_n_list as a string instead of a list reference. It should be print(larger_than_n_list)
  • missing if-statement to compare each element in the list with the value in the argument passed.
  • missing call to the display_larger_than_n_list function

A sample image output of the code execution is attached.

Ver imagen ibnahmadbello

Following are programs to the given question:

Program Explanation:

  • Defining a method "main" inside the method two-variable "number and number_list" is declared that holds an integer value and a list value.
  • In the next step, multiple print methods are used that prints its calculated value.
  • Inside this, another "display_larger_than_n_list" method is called that accepts value in the parameter.
  • In "display_larger_than_n_list" method an empty list "larger_than_n_list" is declared.
  • In the next line, it defines a loop inside the conditional statement that checks list value that is greater than parameter value and prints its value.

Program:

def main():#defining a method main

   number = 5#defining an integer variable

   number_list = [1,2,3,4,5,6,7,8,9,10]#defining a list number_list that holds integer numbers in it.

   print('Number', number)#printing number variable value  

   print('List of numbers:/n', number_list, sep='')#print list value

   print('List of numbers that are larger than ', number, ':', sep='')#print the list value that is larger than 5

   display_larger_than_n_list(number, number_list)#calling the method

def display_larger_than_n_list(n, n_list):#Defining a method that takes two parameter

   larger_than_n_list = []#Defining an empty list.

   for valie in n_list:# defining a for loop that holds list value  

       if valie > n:#defining if block that check value

           print(valie)##print list value

main()#calling main

Output:

Please find the attached file.

Learn more:

brainly.com/question/19195262

Ver imagen codiepienagoya
ACCESS MORE