我正在用 python 构建一个非常基本的老虎机。这是我正在做的第一个 python 代码,并且正在遵循 ytb 教程。不知何故,当我测试代码时,我在终端中没有得到正确的结果。
MAX_LINES = 3
def deposit():
while True:
amount = input("What would you like to deposit? $")
if amount.isdigit():
amount = int(amount)
if amount > 0:
break
else:
print("Amount must be greater than 0.")
else:
print("Please enter a number.")
return amount
def get_number_of_lines():
while True:
lines = input("Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ")
if lines.isdigit():
lines = int(lines)
if 1 <= lines <= MAX_LINES:
break
else:
print("Enter a valid number of lines.")
else:
print("Please enter a number.")
return lines
def main():
balance = deposit()
lines = get_number_of_lines()
print(balance, lines)
main()
这是我到目前为止编写的代码。
这是我在终端中得到的内容(我在 VsCode 中执行此操作)。
What would you like to deposit? $200
Enter the number of lines to bet on (1-3)? 3
None None. \<\<this should say 3 ...
而且我还没有得到,但找到这个问题的答案很困难,YouTube 视频下还有其他一些人在终端中遇到相同的输出。
您需要正确缩进
return ...
行:
MAX_LINES = 3
def deposit():
while True:
amount = input("What would you like to deposit? $")
if amount.isdigit():
amount = int(amount)
if amount > 0:
break
else:
print("Amount must be greater than 0.")
else:
print("Please enter a number.")
return amount
def get_number_of_lines():
while True:
lines = input("Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ")
if lines.isdigit():
lines = int(lines)
if 1 <= lines <= MAX_LINES:
break
else:
print("Enter a valid number of lines.")
else:
print("Please enter a number.")
return lines
def main():
balance = deposit()
lines = get_number_of_lines()
print(balance, lines)
main()