We help IT Professionals succeed at work.
Private
Troubleshooting Question

python code assistance.

nav2567
nav2567 asked
on
25 Views
Last Modified: 2020-11-18
Hello,

I am getting these error with the below code.  Please advise how to fix.  Thanks!

TypeError: input expected at most 1 argument, got 5

maxnumber = 10
userstring = input(“Please enter a number”)
usernum = int(userstring)

While usernum > maxnumber:
   print("You enter:”,usernum,”The biggest number is”,maxnumber,”Please enter again”)
   userstring = input(“You enter:”,usernum,”The biggest number is”,maxnumber”,”Please enter again”)
   usernum=int(user string)

print(“Thanks for entering:”,usernum)

Comment
Watch Question

HainKurtSr. System Analyst
CERTIFIED EXPERT

Commented:
you have to use + in print function

print(You enter:”,usernum,”The biggest number is”,maxnumber,”Please enter again”) 
>>>
print(You enter: ” + usernum + ” The biggest number is ” + maxnumber + ” Please enter again”)
NorieAnalyst Assistant
CERTIFIED EXPERT
Try this.
maxnumber = 10
userstring = input('Please enter a numberL\n')
usernum = int(userstring)

while usernum > maxnumber:
   userstring = input(f'You enter:{usernum}, The biggest number is: {maxnumber}, Please enter again:\n')
   usernum=int(userstring)

Open in new window

Author

Commented:
HainKurt, I am getting another type error which is "can only concatenate str (not "int") to str

Norie, I tried your way as well.  It is not showing usernum and maxnumber as numbers but this result:

You enter:(usernum), The biggest number is: (maxnumber), Please enter again:
NorieAnalyst Assistant
CERTIFIED EXPERT
Can you post the exact code you are using?

Author

Commented:
I updated the original code I submitted, but it is pretty much similar.  Please check again.  

Author

Commented:
run it and you will see the error.  Any number smaller the maxnumber will be printed fine.  
NorieAnalyst Assistant
CERTIFIED EXPERT
What happens if you copy and paste the code I posted and run it?

Author

Commented:
I will try that later and update.  Thanks again...

Author

Commented:
Norie,

I think I tried it this morning and I got the below if I enter the number bigger than the maxnumber.  

You enter:(usernum), The biggest number is: (maxnumber), Please enter again: 

Instead, I want the following:

You enter:12, The biggest number is: 10, Please enter again:

I will run it again later and update.  
Analyst Assistant
CERTIFIED EXPERT
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Ah...I see.  I have to use the curly bracket instead.  I think it will work.  I will try.  Thank you!!!
HainKurtSr. System Analyst
CERTIFIED EXPERT
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Yes, HainKurt, I think your way will work too.  I am going to try both ways and update again.  Thanks again. 

Author

Commented:
All is well.  Thanks everyone!!!