Negatyp
Negatyp

Reputation: 45

How to numerate input

I wanted to ask how to make the instructions for the user on the screen:

enter 1 number
enter 2 number

not just

enter the numbers

Thank you in advance!

numbers  = []
limit = 2

for x in range(limit):
    numbers1 = int(input('enter numbers: '))
    numbers.append(numbers1)

print(numbers)

Upvotes: 0

Views: 54

Answers (2)

Rodrigo Rodrigues
Rodrigo Rodrigues

Reputation: 8576

You already have an index number on each iteration, that is the variable x. You can just print it together with your input text.

for x in range(limit):
    number = int(input(f'enter number {x}: '))
    numbers.append(number)

If you want so start with 1 instead of 0, you can change your range:

for x in range(1, limit+1):
    number = int(input(f'enter number {x}: '))
    numbers.append(number)

Upvotes: 1

Ahmed AEK
Ahmed AEK

Reputation: 17990

as of python 3.6 this is a correct way to do it using f-strings.

for x in range(limit):
    numbers1 = int(input(f'enter {x+1} number: '))
    numbers.append(numbers1)

Upvotes: 1

Related Questions