首页 > 解决方案 > 当用户为变量 resp_2 输入 N 或 N 时,从两个循环中跳出

问题描述

当用户输入 resp_2 作为 n 或 n 时使用 break 是否有助于打印两个打印语句并且对于 y 或 Y 循环迭代?

while True:
    resp_1=int(input("Select any option from 1-5 : "))
    while True:
        if True:
            if resp_1==1:
            #MENSTRUAL CYCLE TRACKER - SHINE
            
            #intro shine
                print("SHINE")           #BIG SHINE
                split_()
                print("HI",n_up," I am SHINE\n")
                print("I will help you to organise your menstrual cycle\n")
                print("No need to feel shy or embarassed")
                print("Menstrual cycle is like any other process of our body & its better to know prehand when it occurs!!")
                split_()
            #user information   
                print("Please enter the following credentials:!!!!!\n")
                print(n_up," When did your last cycle begin?\n")
                #date
                mon= int(input("MONTH (mm) -- "))
                da= int(input("DAY (dd) -- "))
                year= int(input("YEAR (yyyy)-- "))
                last= int(input("HOW MANY DAYS DOES YOUR NORMAL PERIODS LAST? -- "))
            
                #main
                month= {1:"JANUARY",2:"FEBRUARY",3:"MARCH",4:'APRIL',5:'MAY',6:'JUNE',7:'JULY',8:'AUGUST',9:'SEPTEMBER',10:'OCTOBER',11:'NOVEMBER',12:'DECEMBER'}
                day= {"JANUARY":30,'FEBRUARY':28,'MARCH':31,'APRIL':30,'MAY':31,'JUNE':30,'JULY':31,'AUGUST':31,'SEPTEMBER':30,'OCTOBER':31,"NOVEMBER":30,'DECEMBER':31}
                
                #leap year check for february
                if year%4==0:
                    if mon==2:
                        mtch=month.get(mon)
                        day1=29
                    else:
                        mtch=month.get(mon)
                        day1=day.get(mtch)
                        
                else:
                     mtch=month.get(mon)
                     day1=day.get(mtch)
                   
                     
                #formulae & logic
                n=(da+28+last)
                
                #specify result
                
                if day1==30 or 31 or 29 or 28:
                    v=mon+1
                    next_mon= month.get(v)
                    nxt_day1=day.get(next_mon)
                    next_day=n-nxt_day1
                    print("\nNEXT CYCLE STARTS ON:",next_mon,next_day,year)
                    
                elif n<30:
                    mtch=month.get(mon)
                    print("NEXT CYCLE STARTS ON:",mtch,n,year)
                    
            
        #keep at last        
    resp_2=input("Do you want to continue? (Y/N) -- ")
    if resp_2 == 'Y' or 'y':
        True
    elif resp_2 == 'n' or 'N':
        break
        
print("THANK YOU",n_up,"DO COME BACK SOON")
print("HASTA LA VISTA!!!!!!")

标签: python-3.xbreak

解决方案


推荐阅读