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
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!
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
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String