day_06 guess the age of the game, three menus (homework)

I guess the age of the game:

Claim:

    Allows the user to try up to three times 
    after every three attempts, if you have not guessed, asked whether the user would like to continue playing, if the answer Y or y, then allowed to continue to guess three times, this back and forth, if the answer N or n , you exit the program 
    if guessed it, there are three selection bonus opportunity, do not reward can leave at any time, and print a list of the prizes to the user to see;
= COUNT 0 
real_age = 19 
goods_list = [
     ' Barbie ' ,
     ' Transformers ' ,
     ' pig Page ' ,
     ' Spider-Man ' ,
     ' model airplanes ' ,
     ' Inflatable Doll ' 
] 
customer_goods_list = [] 
Tag = True
 the while Tag : 
   Age = the INPUT ( ' Please guess the true age (q quit) >>>: ' ) .strip () Lower ().
    IF Age == 'q' : BREAK 
   IF  not age.isdigit ():
        Print ( ' Please enter a purely numeric! ' )
        The Continue 
   Age = int (Age)
    IF Age == real_age:
        Print ( ' !! Congratulations, you guessed it, you have three choice awards ! opportunities ' ) 
       choice_count = 0
        the while True:
            for index, Good in the enumerate (goods_list, 1 ):
                Print (index, Good) 
           choice = the INPUT ( ' Please select a prize (or press q to exit directly) >>>:' .) .Strip () Lower ()
            IF Choice == ' Q ' : BREAK 
           IF  Not choice.isdigit ():
                Print ( ' Enter a number! ' )
                Continue 
           Choice = int (Choice) -1
            IF Choice Not  in Range (len (goods_list)):
                Print ( ' within a selected range not prize. Please reenter! ' )
                Continue 
           the else : 
               choice_count + =. 1
                Print (F 'Your choice of prizes: {goods_list [choice]}, there are {3-choice_count} chance! ' ) 
               Customer_goods_list.append (goods_list [Choice]) 
           Print (f ' your prize list: customer_goods_list {} ' )
            IF choice_count == 3: BREAK 
       BREAK 

   elif Age> real_age:
        Print ( ' ! Guess big ' )
        the Continue 
   the else :
        Print ( ' ! smaller guess ' ) 
   COUNT + =. 1
    IF COUNT ==. 3 :
        the while Tag: 
           again_choicethe INPUT = ( ' ? y also playing three times you lose playing three times, or lose n exit >>>: ' ) .strip () Lower ().
            IF again_choice == ' y ' : 
               COUNT = 0
                BREAK 
           IF == again_choice ' n- ' : 
               Tag = False
                Continue 
           the else :
                Print ( ' input is incorrect, please try again! ' )

Three-level menu:

  1. Print provincial, municipal and county levels menu

  2. Go back one level

  3. You can exit the program at any time

the MENU = {
     ' Beijing ' : {
         ' Haidian ' : {
             ' Wudaokou ' : {
                 ' SOHO ' : {},
                 ' NetEase ' : {},
                 ' Google ' : {} 
            }, 
            ' Zhongguancun ' : {
                 ' iQIYI ' : {},
                 ' car home ' : {},
                 ' the youku ' : {} 
            },
            ' Kamiji' : {
                 ' Baidu ' : {} 
            } 
        }, 
        ' Changping ' : {
             ' River ' : {
                 ' Old Boy ' : {},
                 ' Northern ' : {} 
            }, 
            ' Tiantongyuan ' : {},
             ' Huilongguan ' : {} 
        }, 
        ' sun ' : {},
         ' East ' : {} 
    }, 
    ' Shanghai ' :
        {
        'Minhang " : {
             " People's Square " : {
                 ' Fried Chicken ' : {} 
            } 
        }, 
        ' Zhabei ' : {
             ' Train war ' : {
                 ' Ctrip ' : {} 
            } 
        }, 
        ' Pudong ' : {} 
    } 
    ' Shandong ' : {}, 
} 
Layers = [MENU,]
 the while True:
     IF len (Layers) == 0: BREAK 
    of CURRENT_LAYERS=layers[-1]
    #print(current_layers,type(current_layers),'=================')
    for key in current_layers:
        print(key)
    choice=input('请选择(b返回上一层,q直接退出)>>>:').strip()
    if choice=='b':
        layers.pop(-1)
        #print(layers,'+++++++++++++++++')
        continue
    if choice=='q':break
    if choice not in current_layers:continue
    else:
        layers.append(current_layers[choice])
        # for i in layers:
        #     print(i,'@@@@@@@@@@@@@@@@@@@@')
        # print(layers,'-------------------------',len(layers))
        #print(current_layers[choice],type(current_layers[choice]),'**********************')

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhangchaocoming/p/11520208.html