我现在学习Python已经两个星期了,在没有任何帮助的情况下,我试着单独做一个项目,结果陷入了这个语法错误。你知道吗
我的第二个代码显示一切正常,但最后它说没有。如果我没有返回代码中的任何内容,为什么会收到该消息?你知道吗
该代码的想法是创建一个掷硬币游戏,玩家必须在正面或反面下注,最后必须显示他拥有的总金额。你知道吗
附言:别客气,我可能犯了一些大错误。:(
import random
money = 100
def heads(bet):
num = random.randint(1, 10)
if (num % 2== 0):
print("It's heads and you won " + str(bet) + " In total you have " + str(money_w))
money_w= money + bet
else:
print("It's tails you lost " + str(bet) + " In total you have " + str(money_l))
money_l= money - bet
def tails(bet):
num = random.randint(1, 10)
if (num % 2== 0):
print("It's tails you won " + str(bet) + " In total you have " + str(money_w)
money_w= money + bet
elif:
print("It's heads and you lost " + str(bet) + " In total you have " + str(money_l))
money_l= money - bet
def coin_flip(guess, bet):
result= random.randint(1,2)
if (guess == "Heads" and result == 1) or (guess == "Tails" and result ==2):
print("You guessed correctly! You won " + str(bet))
else:
print("You didn't guess. You lost " + str(bet))
以下几点可以帮助您:
money_w
和money_l
;翻转这两个语句tails()
和heads()
不更新money
或返回任何内容,因此money
始终为100相关问题 更多 >
编程相关推荐