Answer:
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
<u>Output</u>:
[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"