投币程序中的名称错误

2024-09-30 01:27:31 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: youforinputrawifrandompasspress

热门问题