How to numerate input

Question:

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)
Asked By: Negatyp

||

Answers:

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)
Answered By: Ahmed AEK

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)
Answered By: Rodrigo Rodrigues
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.