Ask Question
20 August, 13:44

Write a function called check_nums that takes a list as its parameter, and contains a while loop that only stops once the element of the list is the number 7. What is returned is a list of all of the numbers up until it reaches 7.

+2
Answers (1)
  1. 20 August, 15:48
    0
    Following are the program in the Python Programming Language:

    def check_nums (length) : #define function

    my_lst=[] #set list type variable

    n=0 #set integer type variable

    while (length[n]! = 7) : #set the while loop

    my_lst. append (length[n]) #append liat in my_lst

    n+=1 #increament in n

    if (len (length) = =n) : #set if condition

    break #break the loop

    return my_lst #return the list

    l=[4,6,2,55,16,7,81] #set list variable and assign list init

    print (check_nums (l)) #call and print the function

    Output:

    [4, 6, 2, 55, 16]

    Explanation:

    Here, we define a function "check_nums () " and pass an argument in its parentheses inside the function,

    we set list data type variable "my_lst" and integer type variable "n" we set while loop and pass the condition is the variable "length[n]" is not equal to the 7 then, the value of "length[n] " is appends to the variable "my_lst" and increment in the variable "n" by 1. we set if condition and check when the length of the variable "length" is equal to the variable "n" then, break the loop and return the value of "my_lst".

    Finally, set the list type variable "l" and assign the list of numeric value in it then, call and print the function "check_nums"
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function called check_nums that takes a list as its parameter, and contains a while loop that only stops once the element of the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers