Question

Write a program that first gets a list of integers from input. The input begins with...

Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value.

Ex: If the input is:

5
50
60
140
200
75
100

the output is:

50
60
75

The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75. The 100 indicates that the program should output all integers less than or equal to 100, so the program outputs 50, 60, and 75.

Such functionality is common on sites like Amazon, where a user can filter results.

Your code must define and call the following two functions:
def get_user_values()
def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold)

Utilizing functions will help to make your main very clean and intuitive.

Note: This is a lab from a previous chapter that now requires the use of functions.

LAB

ACTIVITY

8.28.1: LAB: Output values in a list below a user defined amount - functions

0 / 10

Note. please the other answers you have on here for this same question are not working. I really need help with this question. My assignment is due today. Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def get_user_values():
    n = int(input())
    lst = []
    for i in range(n):
        lst.append(eval(input()))
    t = eval(input())
    output_ints_less_than_or_equal_to_threshold(lst, t)

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):
    for x in user_values:
        if(x <= 100):
            print(x)

get_user_values()

Output:

140 100 60 Process finished with exit code o

Add a comment
Know the answer?
Add Answer to:
Write a program that first gets a list of integers from input. The input begins with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA Write a program that first gets a list of integers from input. The input...

    IN JAVA Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75...

  • Write a program that first gets a list of integers from the input and adds them...

    Write a program that first gets a list of integers from the input and adds them to an array. The input begins with an integer indicating the number of integers that follow (Your program should work for any size of the array). Then, get the last value from the input, and output all integers less than or equal to that value by iterating through the array. Ex: If the input is: Enter the number of integers: 5 Enter integer 1:...

  • *Coral Language* Write a program that first gets a list of six integers from input. The first five values are the intege...

    *Coral Language* Write a program that first gets a list of six integers from input. The first five values are the integer list. The last value is the upper threshold. Then output all integers less than or equal to the threshold value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Such functionality is common on sites like...

  • Coral Language Please to thanks Write a program that first gets a list of 5 integers...

    Coral Language Please to thanks Write a program that first gets a list of 5 integers from input. Then, get another value from the input, and output all integers less than or equal to that value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Then, output a newline. Such functionality is common on sites like Amazon, where...

  • Please draw a flow chart for each method please and thank you. Write a program that...

    Please draw a flow chart for each method please and thank you. Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 50 60 140 200 75 100 the...

  • in python and can you tell me why i am wrong? Thank you ZyBooks Python M...

    in python and can you tell me why i am wrong? Thank you ZyBooks Python M X zy cS 171: Computer x zy 11.9. LAB: Output x C Write A Program 1 x Slack | Hiu Nguy TG Python Program t x p ython - Getting x +. - 5 x € → e l earn.zybooks.com/zybook/DREXELCS171 Winter2020/chapter/11/section/9 Help/FAQ Kuanyu Lai - = zyBooks Bake My library > CS 171: Computer Programming home> > 11.9: LAB: Output values in a list...

  • Write a program that reads a list of integers ending with a negative, and that then...

    Write a program that reads a list of integers ending with a negative, and that then outputs that list in reverse. After the negative that ends the list, a character indicates what character should separate the output integers. If the input is: 3 5 2 - 1 * the output is: 2*5*3 LAB ACTIVITY 7.16.1: LAB: Reverse a list, with separating characters 2 / 10 main.cpp Load default template... 6 7 8 int numbers [100],i=0, num, size; char character; cin>>num;...

  • You will develop a program that will read a list of integers into an array. Data...

    You will develop a program that will read a list of integers into an array. Data entry will end when a negative number is entered. When data entry is completed, the program will ask for a nominal value. When this number is entered, two lists will be displayed-one containing the numbers equal to or above the nominal value and a second one with the values below the nominal. A typical output is shown below: This program inputs a list of...

  • Write a program that asks the user to input 5 integers in an Array named "gradearray.”...

    Write a program that asks the user to input 5 integers in an Array named "gradearray.” then passes gradearray in a function to find how many passing grades exist. (passing grades are between 60 and 100) Input elements for the gradearray : 67 43 90 100 75 There are 4 passing grades There are 1 failing grades

  • 5.23 LAB: Adjust values in a list by normalizing When analyzing data sets, such as data...

    5.23 LAB: Adjust values in a list by normalizing When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, adjust each integer in the list by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT