Issue
I need make program that asks, how many numbers I want to add list example 5, then it asks individually those numbers and last prints out list in that order. I otherwise got to work but don't know how to do that part when it asks individually those numbers.
This is what program should work.
How many numbers you want to add list: 5
Number 1: 76
Number 2: 9
Number 3: 32
Number 4: 77
Number 5: 3
List:
[76, 9, 32, 77, 3]
And here is my code:
amount = int(input("How many numbers do you want to add to the list? "))
numbers = []
numbers.append()
print(numbers)
Solution
Try this.
I am using f-strings
here. This only works in Python 3.6+.
n = int(input('How many numbers do you want to add to the list? '))
lst = []
for i in range(1,n+1):
temp = int(input(f'Number {i}: '))
lst.append(temp)
print(f'List:\n{lst}')
Output:
How many numbers do you want to add to the list? 5
Number 1: 67
Number 2: 6
Number 3: 45
Number 4: 9
Number 5: 1
List:
[67, 6, 45, 9, 1]
Answered By - Ram Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.