簡體   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