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
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) + " :"))