这是我的简单硬币翻转程序的代码。唯一的问题是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