Hello, please help me to list the results of Python!

Asked 2 years ago, Updated 2 years ago, 18 views

x = (int(input("How many items do you want in your list? ")))
for i in range(1, x + 1):
    input("Enter string " + str(i) + ":")

Put 4 list numbers here

Enter string 1:Apple Enter string 2:Toy Enter string 3:Banana Enter string 4:Doll

Put it in

["Apple", "Toy", "Banana", "Doll"] I don't know how to express it. I tried everything I knew, but only the last result was printed. Help me! ㅜ<

python

2022-09-22 18:40

1 Answers

After setting the list type variable for the item, You can take the input from the for statement and put it in the variable.

Please refer to the code.

x = (int(input("How many items do you want in your list? ")))
items = []
for i in range(1, x + 1):
    items.append(input("Enter string " + str(i) + ":"))

print(items)


2022-09-22 18:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.