简体   繁体   中英

Higher/lower game inputs

having trouble figuring out why my input for z isn't working. i type in my inputs for lower and upper, and then don't get the chance to enter any input for z.

TypeError: input expected at most 1 argument, got 4

print("Welcome to the higher/lower game, Bella!\n")

x = int(input("Enter Lower Bound: "))
y = int(input("Enter Upper Bound: "))
z = int(input("Great, now guess a number between", x, "and", y))

It's because you have two strings and two variables inside your input for z.

Change the message to use string formatting so it is all in one piece:

'Great, now guess a number between {} and {}'.format(x, y)

for this, I would suggest either using .format or an f string

for .format

z = int(input('Great, now guess a number between {} and {}'.format(x, y)))

for an f string

z = int(input(f"Great, now guess a number between {x} and {y}"))

I would personally use f string because I find it much simpler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM