22.5k views
0 votes
Write a loop to populate the list user_guesses with a number of guesses. The variable num_guesses is the number of guesses the user will have, which is read first as an integer. Read integers one at a time using int(input()). Sample output with input: '3 9 5 2' user_guesses: [9, 5, 2]

1 Answer

1 vote

Answer:

num_guesses = int(input())

user_guesses = []

for i in range(num_guesses):

x = int(input())

user_guesses.append(x)

print(user_guesses)

Step-by-step explanation:

This solution is provided in Python

This line prompts the user for a number of guesses

num_guesses = int(input())

This line initializes an empty list

user_guesses = []

This loop lets user input each guess

for i in range(num_guesses):

This line takes user input for each guess

x = int(input())

This appends the input to a list

user_guesses.append(x)

This prints the user guesses

print(user_guesses)

User Sindri Traustason
by
5.3k points