这是一个简单的掷硬币程序的代码。唯一的问题是h
和t
没有定义,尽管我希望它们是userChoice
变量。
我错过了什么或者做得不对
class Heads_or_Tails:
import random
print("Enter 'h' for Heads and 't' for Tails.")
userChoice = raw_input()
userChoice = raw_input()
try:
input("Press Enter to see result.")
except SyntaxError:
pass
a = 1
b = 2
machineChoice = random.randrange(1, 2, 2)
if(machineChoice == a):
if(userChoice == h):
print("You win!")
elif(userChoice == t):
print("You lose.")
else:
pass
if(machineChoice == b):
if(userChoice == h):
print("You lose.")
if(userChoice == t):
print("You win!")
else:
pass
try:
input("Press Enter to exit.")
except SyntaxError:
pass
目前没有回答
相关问题 更多 >
编程相关推荐