【发布时间】:2015-05-27 04:15:01
【问题描述】:
我在我的 Raspberry Pi 上做了一个基本的随机程序,它有点像这样。
import random
print ("Welcome to the PC Expo's new game, PC Dispenser, what will you win?")
WinorLose = random.randint(1, 1000)
if WinorLose <100:
print ("You won a Nintendo Wii.")
elif WinorLose >200:
print ("You won a Sony PSP.")
elif WinorLose > 300:
print ("You won a Nintendo Wii U.")
elif WinorLose > 400:
print ("You won a Sony PS Vita.")
else:
print ("Not your lucky day, Try again.")
print ("Thank you for the visit.")
如果你不知道它做了什么,它有机会为你提供一个虚拟 PSP、Wii U 等。但它所做的只是打印“你赢得了索尼 PSP”或“不是你的幸运日,再试一次”。怎么了?有什么修复吗?
【问题讨论】:
标签: python if-statement random fall-through