繁体   English   中英

"计算函数内的尝试次数"

[英]Counting attempts within a function

我对 Python 还是很陌生,对为什么我的尝试计数器没有增加感到困惑。

def start_game():
    print("\nWelcome to A Python Game")
    print("Choose one of the following:")
    print("1) Play game")
    print("2) About")
    print("3) Quit")
    firstchoice()

def firstchoice():
    max_attempts = 3
    attempts = 0
    while attempts < max_attempts:
        choice = input("> ")
        if choice == "1":
            game()
        elif choice == "2":
            gameabout()
        elif choice == "3":
            return None
        else:
            attempts =+ 1
            print("Invalid choice.")
            print("Attempts to successfully get past the main menu: ", attempts)

start_game()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM