Python - 当尝试 运行 代码时没有任何反应。我什至没有收到错误
Python - When trying to run the code nothing happens. I don't even get an error
我正在尝试使用 Python 创建一个小型博彩应用程序,当我尝试 运行 该程序时,什么也没有发生。我正在使用闲置。
这是我的代码:
def bet():
#balance = 100
x = 0
with open("bal.txt", "r") as f:
for l in f:
bal = (sum([int(a) for a in l.split()]))
while bal > 0:
print ("Your balance is: " + str(balance) + " credits.")
while x == 0:
print ("Enter the amount you would like to bet:")
bet = int(input())
if bet > bal:
x = 0
elif bet < 0:
x = 0
else:
x = 1
print ("Pick a number between 1 and 20")
num = int(input())
convbal = bal - bet
print ("Your bet is now locked in...")
print (" ")
print (" ")
import random
rannum = random.randint(1, 20)
print ("Your guess was: " + str(num))
print (" ")
print ("The random number was: " + str(rannum))
if rannum == num:
print ("WINNER")
bal = bal + (bet * 2)
else:
print ("LOSER")
print ("")
print ("")
这是我在 shell 中收到的结果:
任何想法都会很棒,谢谢:)
代码所做的唯一一件事就是定义一个名为 bet
的函数。您可以在 IDLE shell 中键入 bet()
来调用它,或者将 bet()
放在文件底部(不要缩进!)以自动调用它。
检查 bal.txt 可以打开并且它至少有一行总和 > 0。这里的问题是您的条件之一不合格
我正在尝试使用 Python 创建一个小型博彩应用程序,当我尝试 运行 该程序时,什么也没有发生。我正在使用闲置。 这是我的代码:
def bet():
#balance = 100
x = 0
with open("bal.txt", "r") as f:
for l in f:
bal = (sum([int(a) for a in l.split()]))
while bal > 0:
print ("Your balance is: " + str(balance) + " credits.")
while x == 0:
print ("Enter the amount you would like to bet:")
bet = int(input())
if bet > bal:
x = 0
elif bet < 0:
x = 0
else:
x = 1
print ("Pick a number between 1 and 20")
num = int(input())
convbal = bal - bet
print ("Your bet is now locked in...")
print (" ")
print (" ")
import random
rannum = random.randint(1, 20)
print ("Your guess was: " + str(num))
print (" ")
print ("The random number was: " + str(rannum))
if rannum == num:
print ("WINNER")
bal = bal + (bet * 2)
else:
print ("LOSER")
print ("")
print ("")
这是我在 shell 中收到的结果:
任何想法都会很棒,谢谢:)
代码所做的唯一一件事就是定义一个名为 bet
的函数。您可以在 IDLE shell 中键入 bet()
来调用它,或者将 bet()
放在文件底部(不要缩进!)以自动调用它。
检查 bal.txt 可以打开并且它至少有一行总和 > 0。这里的问题是您的条件之一不合格