Home > Blockchain >  input expected at most 1 argument, got 2 python
input expected at most 1 argument, got 2 python

Time:10-23

I keep receiving this error (TypeError: input expected at most 1 argument, got 2) and I can't figure out why. The goal of the code is to keep asking for a number until that number is between one and a variable called n.

def enterValidNumber(n):
     while True:
         num = int(input("Input a number from 1 to", n)) 
         if num >= 1 and num <= n:
             break

enterValidNumber(17)

CodePudding user response:

Yes, you are right; you are giving two parameters to input. To put n into the prompt string, you can use an f-string:

num = int(input(f"Input a number from 1 to {n}"))

CodePudding user response:

You can always go with j1-lee's answer but I would have another suggestion:

num = int(input("Input a number from 1 to "   str(n)))

this would work well too!

  • Related