Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error coming when i try to take input for 10 numbers with a variable in the input placeholder text

hello so my main objective is to ask user for 10 numbers and then show them the sum of those 10 numbers provided by user

sum=0
for i in range(1,11):
    num=int(input("enter number",i," :"))
    sum=sum+num
print("The sum of given 10 numbers is :",sum)

this is my code but its giving me error in Line 3
saying
num=int(input("enter number",i," :")) TypeError: input expected at most 1 argument, got 3

what I did was to make a variable sum and initialize it to 0 then make a for loop

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for i in range(1,11): 

that will run exactly 10 times and then inside that for loop I asked users for input so that will ask to input numbers 10 times now under this input display text
for eg :

num=int(input('Enter Number 1 :")) 

instead of number 1 I wanted to make it dynamic so i put i instead of it

num=int(input("Enter number ",i," :")) 

to make it ask new number every loop
like
enter number 1 in first loop then enter number 2 in second loop and till 10th loop.
but it gave me error I mentioned above.

please help me where i made mistake and what i did wrong.
thank you

>Solution :

The python input() method only takes 1 argument and you are providing 3!
So to chain these arguments together simply use thy + operator instead of ,
So it should look like:

num=int(input("Enter number " + str(i) + " :")) 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading