原始输入未正确返回

2024-10-01 09:32:20 发布

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

def daenerys():
    Name = raw_input("Who goes there?")

    if ("Daenerys of the House Targaryen, the First of Her Name, The Unburnt, Queen of the Andals, the Rhoynar and the First Men, Queen of Meereen, Khaleesi of the Great Grass Sea, Protector of the Realm, Lady Regnant of the Seven Kingdoms, Breaker of Chains and Mother of Dragons"):
        print("Welcome, Daenerys.")
    elif ("DHTFHNUQARFMQMKGSPRLRSKBCMD"):
        print("Welcome, Daenerys.")
    elif ("Dany"):
        print("Dany who?")
    else:
        print("Move along, now")

daenerys()

Tags: andofthenameinputrawdeffirst
1条回答
网友
1楼 · 发布于 2024-10-01 09:32:20

你甚至没有检查Name变量。你应该这样做

def daenerys():
    Name = raw_input("Who goes there?")

    if (Name == "Daenerys of the House Targaryen, the First of Her Name, The Unburnt, Queen of the Andals, the Rhoynar and the First Men, Queen of Meereen, Khaleesi of the Great Grass Sea, Protector of the Realm, Lady Regnant of the Seven Kingdoms, Breaker of Chains and Mother of Dragons"):
        print("Welcome, Daenerys.")
    elif (Name == "DHTFHNUQARFMQMKGSPRLRSKBCMD"):
        print("Welcome, Daenerys.")
    elif (Name == "Dany"):
        print("Dany who?")
    else:
        print("Move along, now")

daenerys()

这实际上会检查变量Name是否等于字符串。你知道吗

相关问题 更多 >