191k views
5 votes
Output values below an amount

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:
For coding simplicity, follow every output value by a space, including the last one.
Such functionality is common on sites like Amazon, where a user can filter results.
LAB
ACTIVITY
8.3.1: LAB: Output values below an amount
0 / 10
Submission Instructions
These are the files to get you started.
main.cpp
Download these files
Compile command
g++ main.cpp -Wall -o a.out
We will use this command to compile your code

User Kintalken
by
5.3k points

1 Answer

5 votes

Answer:

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

for value in user_values:

if value < upper_threshold:

print(value)

def get_user_values():

n = int(input())

lst = []

for i in range(n):

lst.append(int(input()))

return lst

if __name__ == '__main__':

userValues = get_user_values()

upperThreshold = int(input())

output_ints_less_than_or_equal_to_threshold(userValues, upperThreshold)

Step-by-step explanation:

User TheKarateKid
by
5.2k points