python - 蟒蛇水果机
问题描述
我正在为随机选择符号的水果机编写代码,但无法找出我哪里出错了。这是代码:
import random
credit = 100
def roll(credit):
sym1 = random.choice(symbols)
sym2 = random.choice(symbols)
sym3 = random.choice(symbols)
print("---Symbols---")
print(sym1, sym2, sym3, "\n")
if (sym1 == sym2 or sym1 == sym3 or sym2 == sym3) and not(sym1 == sym2 == sym3):
print("Winner! +50p")
credit += 50
return credit
elif (sym1 == sym2 == sym3) and sym1 != "Bell":
print("Winner! +£1")
credit = credit + 100
return credit
elif (sym1 == sym2 == sym3) and (sym1 == "Bell"):
print("Jackpot! +£5")
credit = credit + 500
return credit
elif (sym1 == sym2 == "Skull" or sym1 == sym3 == "Skull" or sym2 == sym3 == "Skull") and not(sym1 == sym2 == sym3):
print("Two Skulls! -£1")
credit = credit - 100
return credit
elif (sym1 == sym2 == sym3) and sym1 == "Skull":
print("Three Skulls! Lose all credit")
credit = 0
return credit
else:
print("Loser!")
symbols = ["Cherry", "Bell", "Lemon", "Orange", "Star", "Skull"]
print("You have", credit, "p", "\n")
while True:
print("")
play = input("Roll costs 20p. Would you like to roll? yes/no: ")
print("")
if play == "yes" or "y" or "Yes" or "Y":
if credit >= 20:
roll(credit)
credit -= 20
print("Credit is", credit, "p")
else:
print("You do not have enough money to roll!")
这里的问题是,当一个人获胜时,信用不会添加到信用变量中。然而,20p 总是被拿走。我会非常感谢这里的一些帮助。
谢谢
解决方案
您这样做roll(credit)
但不将值分配回信用。你需要做credit = roll(credit)
。
推荐阅读
- appkit - 在 NSStackView 中对齐控件
- android - 无法连接到配对的蓝牙设备
- html - 在 Urql clint 中打开 ssr 时,我收到以下错误: 没想到服务器 HTML包含
- python-3.x - 来自预先计算的统计数据的箱线图不显示框
- unity3d - Unity 2D 物理材料 2D 问题弹性
- typescript - 打字稿从不输入条件
- selenium - jmeter webdriver没有拾取vars值
- ios - 仅清除颤动 Firebase 消息中的选定通知
- javascript - 在 Vue Router Navigation Guard 中使用 axios
- python - 如何将“flask”配置为仅从浏览器运行文件?