1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergeinik [125]
3 years ago
13

Write a function, sublist, that takes in a list of numbers as the parameter. In the function, use a while loop to return a subli

st of the input list. The sublist should contain the same values of the original list up until it reaches the number 5 (it should not contain the number 5).
Computers and Technology
1 answer:
Alla [95]3 years ago
4 0

Answer:

Following are the code to this question:

def sublist(l):#defining a method list sublist that accepts a list

   val=[]#defining an empty list

   x=0#defining x variable that store value 0

   while(x<len(l)):#defining loop that check x is lessthen list length  

       if(l[x]==5):#defining if block that checks list value equal to 5

           break#using break keyword  

       val.append(l[x])#add value in val list

       x+= 1#increment the value of x variable by 1

   return val#return val

l=[3,4,7,8,5,3,2]#defining list l

print(sublist(l))#using print method to call sublist method

Output:

[3, 4, 7, 8]

Explanation:

  • In the above python code, a method "sublist" is declared that accepts a list, inside the method an empty list "val" and an integer variable x is defined that stores "0"  value.
  • In the method, a while loop is declared that checks list length and define if block to checklist element value equal to "5". which the condition is true it will return before values.
  • In the last step, a list "l" is declared that holds value and used the print method to call sublist to prints its return value.
You might be interested in
________ can contain stacked images, text, and other elements which collectively comprise a Photoshop file.
emmasim [6.3K]
If you don’t mind can u add the picture it helps me Answer the question better
6 0
2 years ago
On a printed circuit board, electronic components will be mounted from the
Likurg_2 [28]
On a printed circuit board, electronic parts will be mounted from the substrate side of the board. The leads jab through the substrate and the copper sheeting that has been carved. The leads are then soldered to the copper.

I hope the answer will help you. 
3 0
3 years ago
Que se trata el RUC<br>​
mariarad [96]
No se senor i no sure
7 0
3 years ago
True or false webcasts are delivered only as prerecorded audio and video content
alexandr1967 [171]
I believe the answer is false
3 0
3 years ago
Which is the another name of automatic sequence control calculator​
Alla [95]

Answer:

IBM Automatic Sequence Controlled Calculator (ASCC)

3 0
3 years ago
Other questions:
  • Who usually signs a collection letter?
    15·2 answers
  • What is looping in QBASIC​
    9·1 answer
  • Mobile phones that function as credit cards are called _____.
    11·1 answer
  • Suppose you have one particular application that is trying to send data on the Internet but none of the data is making it to the
    15·2 answers
  • String[][] arr = {{"Hello,", "Hi,", "Hey,"}, {"it's", "it is", "it really is"}, {"nice", "great", "a pleasure"},
    11·1 answer
  • What is the role of computer in education sector?​
    13·1 answer
  • In 1980, IBM's cheapest computer was more affordable than Apple's.<br><br><br> True<br><br> False
    10·1 answer
  • If a company saw an online photo of you playing basketball, it might try to sell
    5·1 answer
  • What is system software?
    14·1 answer
  • Presentations must have what to be efffective
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!