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
Gennadij [26K]
4 years ago
15

The len function consumes a list and returns its length as an integer. Use the len function to write your own function check_len

gth that consumes a list and returns whether it is 3-5 items long. Call and print this function twice.
Computers and Technology
1 answer:
RideAnS [48]4 years ago
3 0

Answer:

def check_length(mylist):

       length = len(mylist)

       if 3<=length<=5:

               message = "The length of the list is "+str(length)+" items long"

       else:

               message = "The length of the list is not within range of 3 to 5"

       return message

 

mylist = []

print("Press Y to continue input")

cont = 'Y'

while cont == 'Y':

       b = input("Input: ")

       mylist.append(b)

       cont = input("More Input?Y: ")

 

print(check_length(mylist))

print(check_length(mylist))

Explanation:

The program creates an empty list and prompts user for input until user presses a key other than Y

This line declares function check_list

def check_length(mylist):

This line calculates the length of the list passed to the function

       length = len(mylist)

This line checks the length of the list if it is within the range of 3 to 5

       if 3<=length<=5:

This line gets the length of the list if it is between 3 and 5 (inclusive)

               message = "The length of the list is "+str(length)+" items long"

       else:

If otherwise, this line returns that the length is not within range

               message = "The length of the list is not within range of 3 to 5"

This line returns the appropriate message based on the conditional statement above

       return message

The main statement starts here

This line defines an empty list  

mylist = []

This line gives the user instruction on how to input

print("Press Y to continue input")

cont = 'Y'

While the user presses Y, the following while conditional statement is executed

<em>while cont == 'Y': </em>

<em>        b = input("Input: ") </em>

<em>        mylist.append(b) </em>

<em>        cont = input("More Input?Y: ") </em>

 

The next two line calls the function twice

print(check_length(mylist))

print(check_length(mylist))

You might be interested in
Explain how communication managerial efficiency​
kakasveta [241]

Answer:

The efficiency of manager depends upon his ability to communicate effectively with the members of his organisation. It is only through communication that management conveys its goals and desires, issues instructions and orders, allocates jobs and responsibility and evaluates performance of subordinates.

pls tag me brainliest

8 0
3 years ago
A(n) _____ is a flexible tool used to analyze data using reports that do not have a predetermined format.
Mandarinka [93]

Answer:

decision support system

Explanation:

4 0
3 years ago
Which of these graphic elements combine text, illustrations, and color?
Likurg_2 [28]

Answer:

Send the picture.

Explanation:

8 0
3 years ago
Read 2 more answers
How can an Excel table be added to a Word document? Check all that apply.
densk [106]

Answer:

A and B

Explanation:

3 0
4 years ago
3. How can you correct the color of your photos automatically?​
natita [175]

Answer:

use the lightroom

download the app haha

4 0
3 years ago
Read 2 more answers
Other questions:
  • A bug collector collects bugs every day for 5 days. Write a program that keeps a running total of the number of bugs collected d
    12·1 answer
  • failure of the _ cylinder will often result in sudden unexpected loss of the ability to stop the vehicle
    10·1 answer
  • Can anybody do Algorithm 2 for me (with Python).<br> Answer = 25 points.
    13·1 answer
  • How does a search engine use algorithms to provide search results?
    15·2 answers
  • Add me on blizzard none of my friends play ow<br> NADERJABER#2530
    8·1 answer
  • Graphics created within Illustrator CC are always vector graphics true or false
    9·1 answer
  • A palindrome is a string that reads the same from left to right and from right to left. Design an algorithm to find the minimum
    15·1 answer
  • Once you fix the bug in a code, what is the last thing you should do?
    6·1 answer
  • write a function that given an integer n returns the smallest integer greater than n the sume of whose digits is twice as big th
    13·1 answer
  • What is not recyclable in a<br> hybrid car<br> hydrogen car<br> petrol car
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!