简体   繁体   English

更高/更低的游戏输入

[英]Higher/lower game inputs

having trouble figuring out why my input for z isn't working.无法弄清楚为什么我的 z 输入不起作用。 i type in my inputs for lower and upper, and then don't get the chance to enter any input for z.我输入了下限和上限的输入,然后没有机会为 z 输入任何输入。

TypeError: input expected at most 1 argument, got 4 TypeError:最多输入 1 个参数,得到 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.这是因为您的 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为此,我建议使用.format或 f 字符串

for .format对于.format

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

for an f string对于 f 字符串

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我个人会使用 f 字符串,因为我发现它更简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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