我正在尝试使用Python创建一个小型投注应用程序,当我尝试运行程序时,没有任何事情发生。我正在使用IDLE。 这是我的代码:
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中收到的结果:
任何想法都会很棒,谢谢:)
答案 0 :(得分:2)
代码所做的唯一事情就是定义一个名为bet
的函数。您可以在IDLE shell中键入bet()
来调用它,或者将bet()
放在文件的底部(不缩进!)以自动调用它。
答案 1 :(得分:0)
检查bal.txt可以打开,并且它至少有一行,其总和是&gt;这里的事情是你的一个条件失败