为什么程序无法正常工作?

时间:2016-04-28 22:01:57

标签: python

我正在为学校做一个项目,其中一项任务是创建一个程序,告诉用户他们花了多长时间正确输入字母表。

无论输入是否正确,它总是说“再试一次”;我不确定我做错了什么。

如果有人能帮助我解决这个问题,我会非常感激。

def game():
    import time

    start_time=time.time()
    alphabet = input("Type in the aphabet :  ")
    alphabet = alphabet.capitalize()

    if alphabet == "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z":
        print("Well done.")
        end_time=time.time()-start_time
        print("It took you :{0:.2f}".format(end_time),"seconds.")
    elif alphabet == "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        print("Well done.")
        end_time=time.time()-start_time
        print("It took you :{0:.2f}".format(end_time),"seconds.")
    else:
        print("Try again....")
        game()
    print()

    again = input("Do you want to try again? Y or N ")
    again = again.capitalize()
    if again == "Y":
        game()
    elif again == "N":
        print("Goodbye.") 
    else:
        print("Try again...")
        game()
game()

1 个答案:

答案 0 :(得分:2)

Str.capitalize只会将第一个字母大写,而不是整个单词。你想要str.upper()