176k views
1 vote
In Python write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the values of the list.

Ex: If the input is:

10
5
3
21
2
-6
the output is:

[10, 5, 3, 21, 2]

Code hints: while user_input >0: #This is the number that is greater than 0 from the list that is entered.

print(user_numbers) #Prints out the numbers greater than zero that are inputted at the top part.

User Patchwork
by
4.7k points

1 Answer

3 votes

See the comments for explanations of what each line does.

Code

integers = [] # Create an empty list to store the values

user_input = int(input()) # Get the first input

while user_input > 0: # Loop as specified

integers.append(user_input) # Add the value to the list

user_input = int(input()) # Get another input

print(integers) # Print the full list

User Pedro Pinheiro
by
4.5k points