繁体   English   中英

更高/更低的游戏输入

[英]Higher/lower game inputs

无法弄清楚为什么我的 z 输入不起作用。 我输入了下限和上限的输入,然后没有机会为 z 输入任何输入。

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))

这是因为您的 z 输入中有两个字符串和两个变量。

将消息更改为使用字符串格式,使其成为一体:

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

为此,我建议使用.format或 f 字符串

对于.format

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

对于 f 字符串

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

我个人会使用 f 字符串,因为我发现它更简单

暂无
暂无

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

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