硬币翻转程序中的NameError

时间:2015-01-29 17:08:23

标签: python python-2.7

这是我的简单硬币翻转程序的代码。唯一的问题是ht未定义,即使我希望这些是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

0 个答案:

没有答案