Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
73 views
in Technique[技术] by (71.8m points)

python - Can't use break in a while-loop


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use not logic to check if board_size is equal to 3, 5, or 7. You can use sys.exit() to exit the program, but make sure to import sys.

import sys

def main():
    
    while True:    
        board_size = int(input("How big playing surface (3/5/7)? "))
        
        if not (board_size == 3 or board_size == 5 or board_size == 7):
            sys.exit()
        else:
            break
    while True:
        games = int(input("How many games do you want to simulate? "))

        if games <1:
            sys.exit()
        else:
            break

    while True:
        scenario = int(input('What scenario (1/2)? '))

        if not (scenario == 1 or scenario == 2):
            sys.exit()
        else:
            break

    print(games, scenario, board_size)

main()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...