我为while循环输入了一个无效的结果,它可以工作,但是在几次之后while循环在花费的时间内不断重复

2024-04-26 06:53:53 发布

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

client_dict = {"NeQua":"High","EmVol":"Moderate","RiVam":"High","EdLis":"Moderate"} 
Intensity_sports = {"High":["swimming","aerobics"],"Moderate":["Basketball","Hiking"]}
def activity_recorder(): 
    def clientID_choice(): 
        global clientid,intensity 
        clientid = input("What client would you like to edit?:") 
        while clientid not in client_dict: 
            clientid = input("\nPlease enter the correct client\nWhat client would you like to edit?:")
        intensity = client_dict[clientid] 
        print("\n"+clientid,"has a",intensity,"intensity\nThe reccomened sports are:") 
        for sports in Intensity_sports[intensity]:
            print("//",sports) 

    **def time_taken():
        global time_spent
        time = [] #The variable time is equal to an empty array
        for sport in Intensity_sports[intensity]:
            try: 
                time_spent = int(input("\nPlease select the minutes spent on "+sport+":"))
                while not 0 <= time_spent <= 120: 
                    time_spent = int(input("\nPlease select the minutes spent on "+sport+" between 0 and 120:")) 
            except:
                print("Please enter a number\nYou will be asked to re enter all your times") 
                time_taken() 
            time.append(time_spent) 
        total_time = 0 
        for time_spent in time: 
            total_time += time_spent 
        print("\n"+clientid+"'s total time spent is",total_time,"minutes")**

    def again(): 
        anotherRecord = input("\nDo you wis to enter another record? Type yes or y or no or n:") 
        while anotherRecord.lower() != "yes" and anotherRecord.lower() != "y" and anotherRecord.lower() != "no" and anotherRecord.lower() != "n":
            anotherRecord = input("Please answer again. Yes or No?") 
        if anotherRecord.lower() == "yes" or anotherRecord.lower() == "y": 
            print("You will now enter a new client record") 
            activity_recorder() 
        else: 
            print("Thank you") 
    clientID_choice()
    time_taken()
    again()
activity_recorder() 

你能测试一下,看看有没有错误,帮我一下吗


Tags: ortoclientyouinputtimedeflower