Help with Python input code error

0
3
Asked By CodeNinja42 On

I'm trying to write a simple Python program to take user input for numbers from 1 to 10 and store them in a list. Here's my code:

a=[]

for i in range(1,11):
b=int(input("enter number ",i))
a.append(b)

print(a)

However, I keep getting an error saying that I've used 2 arguments instead of 1 on the third line. I'm new to Python and really confused. Can anyone explain what I'm doing wrong?

2 Answers

Answered By SyntaxExpert On

Just to add a bit more, if you're using an IDE like VSCode, hovering over `input()` will show you how to use it properly. When you're learning, getting used to checking the documentation is a really good habit! Also, here's a clean version of what your code should look like:

```python
a = []
for i in range(1, 11):
b = int(input(f"enter number {i}"))
a.append(b)
print(a)
```

Give that a shot!

Answered By HelpfulDev On

Hey there! It looks like the issue is with the `input()` function. It only accepts one argument, which is the prompt you want to display to the user. In your case, when you do `input("enter number ", i)`, it's interpreting that as you trying to provide two different inputs.

What you probably want is to format your string to include `i`. So you should change your input line to this:

```python
b = int(input(f"enter number {i}"))
```

This will correctly ask for input like "enter number 1", "enter number 2", etc. Hope that helps!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.