[Python] basic grammar exercises 6th day job

'' ' 
Second, the job (each question as a function package) 
1, 99 output the multiplication table, the results are as follows :( prompted for nested loop, the output format) 
2, 1 2 3 4 The four figures, the program design calculate how many other with no repeat of the 3-digit numbers can be composed? What are they? 
3, implemented by a calculator function, respectively, to run the program prompts the user to enter a number 1, number 2, 
and then prompts the user to select: 1 plus [Save] [2] by [3] [4] In addition, depending on the selected completion 
different calculations and returns the result. 
4, when the learning control process, we are talking about the case of a login, we realize now requires a registration process through the code, 
the basic requirements: 
1, run the program, the user is prompted to enter a user name, password, confirm the password again. (Note: All of the user to save a list of data bits stored for each user a dictionary) 
2, the user name interpretation has not been registered, if the user name is registered, then print the results of that username has already been registered (class talked about). 
2, the user name interpretation has not been registered, if the user name is registered, then print the results of that username has already been registered (class talked about). 
'' ' 
# First question 
DEF home_work1 ():
     # Range right open and closed function is left 
    for I in Range (. 1, 10 ):
         for J inRange (. 1, I +. 1 ):
             # : <. 4 representing a left-aligned, end = "", cancel wrap 
            Print ( " {} * {} = {: <. 4} " .format (J, I, I * J) , End = "" )
         # represent the newline 
        Print () 
home_work1 () 

# the second question 
DEF home_work2 (): 
    COUNT = 0
     for I in Range (l, 5 ):
         for J in Range (l, 5 ):
             for K in Range (l, 5 ):
                 IF ! I = J and J = K!and I =! K: 
                    COUNT + =. 1
                     Print ( " {} {} {} " .format (I, J, K))
     Print ( " a total number of {} " .format (COUNT)) 
home_work2 () 

# The third question 
DEF home_work3 (): 
    A = int (iNPUT ( " enter a number: 1 or 2 " )) 
    B = int (iNPUT ( " enter a number: 1 or 2 " )) 
    sELECT = iNPUT ( " Please choose: Save plus [1] [2] [3] In addition to by [4] " )
     IF SELECT == ". 1 " :
         return A + B
     elif SELECT == " 2 " :
         return A - B
     elif SELECT == " . 3 " :
         return A * B
     elif SELECT == " . 4 " :
         return A / B
     the else :
         Print ( " no such options! " )
 # returns the results are received and printed to the console, there is syntax must return to receive data back 
RES = home_work3 ()
 Print(RES) 

# fourth question 
Users = [{ " User " : " HC " , " password " : " 123 " }]
 DEF home_work4 ():
     the while True:
         # registration functionality 
        username = INPUT ( " Please enter a user name: " ) # enter the account number 
        for the User in the Users: # traversing all accounts, determine whether the account exists 
            iF username == the User [ " the User " ]:
                print("The client has been registered " ) # account already exists, please re-enter 
                BREAK 
        the else : 
            password1 = the INPUT ( " Please enter your password: " )   # password 
            password2 = the INPUT ( " Confirm password: " )   # Enter the password again 
            if = password1! password2:
                 Print ( " ! enter two passwords do not match, please re-enter " )   # accounts and passwords do not match, please re-enter 
                the Continue 
            # account does not exist, the password is not repeated, then added to the account list 
            users.append ({ " the User " : username, "password": password2})
            # user["username"] = username
            # user["password"] = password1
            print("注册成功!")
            print(users)
            break

home_work4()

 

Guess you like

Origin www.cnblogs.com/python-test001/p/12365616.html