Three login authentication cart

1. Three login authentication 
is completed Use user login authentication
requirements:
1. The system 4 are automatically created random number as login codes Use like directly do not tangle here...
From the randint Random Import
NUM = 0
verify_code = ""
the while NUM <. 4:
verify_code + = CHR (the randint (65, 90))
NUM = +. 1
Print (verify_code) four random codes #

2. Use Use the user to enter a username and password as well as a verification code.
3. The user may have three log opportunities. However, if you enter the wrong code. not counted
"" " 
1. Three login authentication 
    is completed Use user login authentication 
    requirements: 
        1. The system 4 are automatically created as a random number code directly login authentication Use like herein do not tangle... 
            From the randint Random Import 
            NUM = 0 
            verify_code =" " 
            the while NUM <. 4: 
                verify_code + = CHR (the randint (65, 90)) 
                NUM = +. 1 
            Print (verify_code) four random codes # 

        2. Use Use the user to enter a username and password as well as a verification code. 
        3. The user can there are three chances to log in, but if you enter the wrong code are not counted. 
    program: verification code and user name, password together, but first determine the verification code, verification code in the correct premise, user name or password error be considered within three, otherwise verification code error to blame. 

"" " 
from Random Import randint 

uname = ' alex '
upsw = ' ABC ' 

COUNT = 0
 the while . 1 : 

    # user logs 
    the while COUNT <. 3 :
         # generate codes, will be updated each time re-enter codes 
        NUM = 0 
        verify_code = "" 
        the while NUM <. 4 : 
            verify_code + = CHR (the randint (65, 90))   # uppercase ASCII code 
            NUM = +. 1 Print ( " code: " + verify_code)   # four random codes 
        code = iNPUT ( " Please enter this code: '
        
.) .strip () Upper () 
        name = the INPUT ( ' Please enter your user name: ' ) .strip () 
        password = the INPUT ( ' Please enter your password: ' ) .strip ()
         IF code == verify_code:
             IF name == uname and password == upsw:
                 Print ( ' Login successful ' ) 
                exit ()   # exit the whole program 
            the else :
                 Print ( ' user name or password is incorrect ' ) 
                COUNT + 1 =
                the Continue   # continue within 3 cycles of 
        the else :
             Print ( ' Code error, please try again ' )
             BREAK   # out of the inner loop while 
    the else :   # unsuccessful attempts to enter 
        Print ( ' unsuccessful attempts to enter, can not log ' )
         BREAK   # jump while the outer loop
2, shopping cart operations 
# commodity information:
Goods = [
{ "name": "computer", ". Price": 1999},
{ "name": "mouse", ". Price": 10},
{ "name": " yacht ",". price ": 20 is},
{" name ":" beauty ",". price ": 998},
......
]

# user information:
user = {" username ":" Alex "," password ":" 123456 "}

functional requirements:

1, start the program, enter the user name password, allowing users to enter wages, and then print the product list

2 users based on product number to purchase goods

3, after the user selects a product, testing the balance is enough, direct debit enough, not enough to remind

4, exit, print the purchase of goods and balances

# _ * _ Coding: UTF-8 _ * _ 


"" " 
2, cart job 
    # commodity information: 
    Goods = [ 
        {" name ":" computer ",". Price ": 1999}, 
        {" name ":" mouse ",". price ": 10}, 
        {" name ":" yacht ",". price ": 20 is}, 
        {" name ":" beauty ",". price ": 998}, 
        ...... 
    ] 

    # users information: 
    the user = { "username": "alex", "password": "123456"} 

    functional requirements: 

            1, start the program, enter your user name and password, allowing users to enter wages, and then print the product list 

            2 users according to the commodity No purchase of goods 

            3, after the user selects a product, testing the balance is enough, enough to direct debit, is not enough to remind 

            4, exit, print the purchase of goods and balances 

"""

goods = [
        {"name": "电脑", "price": 1999},
        {"name": "鼠标", "price": 10},
        {"name": "游艇", "price": 20},
        {"name": "美女", "price": 998}

    ]
user = {" Username " : " Alex " , " password " : " 123456 " } 
shopping_cart = {}   # internal storage format is { "computer": [1999, 2], "beauty": [998 2]}, trade name / Price / number 


# user login 
the while 1 : 
    name = the iNPUT ( ' Please enter your user name: ' ) .strip () 
    PSW = the iNPUT ( ' Please enter your password: ' ) .strip ()
     IF name == the user [ ' username '] and psw == user['password ' ]:
         Print ( ' Login successful ' )
         BREAK 
    the else :
         Print ( ' user name or password is incorrect, please re-enter ' ) 

# pay 
the while 1 : 
    salary = the INPUT ( ' Enter salary: ' ) .strip ()
     IF salary .isdigit (): 
        salary = int (salary)
         BREAK 
    the else :
         Print ( ' not a number, please try again ' ) 

# buy 
the while 1:
     # Product List 
    Print ( ' product list ' .center (24, ' - ' ))
     for I in Range (len (Goods)):
         Print ( ' % S% S% S ' % (I, Goods [I] [ ' name ' ], goods [I] [ ' . price ' ])) 

    Choice = iNPUT ( ' enter the product number (Q exit): ' ) .strip ()
     IF choice.isdigit (): 
        Choice = int (Choice)
         IF Choice <len (Goods):   #Within the index range of 
            P = Goods [Choice]   # removed goods 

            IF P [ ' . Price ' ] <= the salary:
                 IF P [ ' name ' ] Not  in shopping_cart:   # cart is the product 
                    shopping_cart [P [ ' name ' ]] = [P [ ' . price ' ], 1]   # set default 
                the else :   # number 1 can add 
                    shopping_cart [P [ ' name ' ]] [1] = + 1 
                the salary- P = [ ' . Price ' ]
                 Continue 
            the else :
                 Print ( ' insufficient funds ' ) 

        the else :
             Print ( ' products do not exist, please re-enter ' )
     elif choice.upper () == ' Q ' :
         IF len (shopping_cart)> 0:
             Print ( ' shopping list ' .center (24, ' - ' )) 
            carts_show = [ ' % S% S% S% S \ n- '% ( ' Product ' , ' monovalent ' , ' number ' , ' total ' )]
             for K, V in shopping_cart.items (): 
                carts_show.append ( ' % S% S% S% S \ n- ' % (K , V [0], V [. 1], V [0] * V [. 1 ])) 

            Print ( '' .join (carts_show))
             Print ( ' balance: ' , the salary)
         BREAK 
    the else :
         Print ( ' not a number, Please re-enter ') 

Reference Code

 

Guess you like

Origin www.cnblogs.com/liangxiaoji/p/10103260.html