+ Exercise 2

# Job (title will do): 
# 1 while loop 2 output. 3. 4. 5. 6. 1. 9 10. 8 
NUM =. 1 while NUM <= 10 :
     IF NUM ==. 7 : 
        NUM + =. 1
         Continue the else :
         Print (NUM) 
        NUM +. 1 = # 2. 1-100 find all the numbers and 
NUM =. 1 
num_sum = 0
 the while NUM <= 100 : 
    num_sum + = NUM 
    NUM + =. 1
 Print (num_sum) # 3. All the outputs 1-100 odd 
NUM =. 1 
odd_sum = 0


    



the while NUM <= 100 : 
    odd_sum + = NUM 
    NUM + 2 =
 Print (odd_sum) 

# 4. Output all even in the 1-100 
NUM = 2 
even_sum = 0
 the while NUM <= 100 : 
    even_sum + = NUM 
    NUM + 2 =
 Print (even_sum) 

# 5. the request 1-2 + 3-4 + 5 ... 99 and the number of all 
NUM =. 1 
num_sum = 0
 the while NUM <= 99 :
     IF NUM% 2 : 
        num_sum + = NUM
     the else :
        num_sum - = NUM 
    NUM + =. 1
 Print (num_sum) 

# 6. The user login (three opportunities retry) 
name = ' Tom ' 
pwd = ' 111 ' 
NUM . 1 =
 the while NUM <=. 3 : 
    i_name = INPUT ( ' Enter Username : ' ) 
    i_pwd = the iNPUT ( ' password: ' )
     IF i_name == name and i_pwd == pwd:
         Print ( ' Login successful ' )
         BREAK
    the else :
         Print ( " user name or password is incorrect (Present {} times) ' .format (NUM)) 
        NUM +. 1 =
 the else :
     Print ( ' has three times the error, please try again later ' ) 

# # 7: Guess Age game 
#      requirements: 
#      allow the user to try up to three times, three times did not guessed, then it exit, if guessed it, print congratulations message and exits 
Age = 50 
l_limit = 1 
h_limit = 99 
NUM = 2
 the while NUM> = 0: 
    gus_age = INPUT ( ' guess oldboy age (~ {{}}): ' .format (l_limit, h_limit)) 
    gus_age =int (gus_age)
     IF gus_age == Age:
         Print ( ' Congratulations, guessed! ' )
         BREAK 
    elif gus_age < Age:
         Print ( ' Unfortunately, small guess, guess at times {} ' .format (NUM)) 
        l_limit = gus_age
     the else :
         Print ( ' I'm sorry, guess big, you can also guess {} times ' .format (NUM)) 
        h_limit = gus_age 
    NUM - = 1
 the else :
     Print ( ' number of runs, then filling it next time ') 

# 8: Guess the age of an upgraded version of the game (optional problems) 
# Requirements: 
#      allow the user to try up to three times 
#      every attempt three times, if you have not guessed, asked whether the user would like to continue playing, or if the answer Y y, allowed to continue three guesses, this shuttle, if the answer N or n, the program exits 
#      how guessed will exit 
Age = 50 
l_limit =. 1 
h_limit = 99 
NUM = 2
 the while NUM> = 0: 
    gus_age = INPUT ( ' guess oldboy age (~ {{}}): ' .format (l_limit, h_limit)) 
    gus_age = int (gus_age)
     IF gus_age == Age:
         Print ( " Congratulations, guessed! ' )
        BREAK 
    elif gus_age < Age:
         Print ( ' Unfortunately, small guess, guess at times {} ' .format (NUM)) 
        l_limit = gus_age
     the else :
         Print ( ' Unfortunately, a large guess, guess at times {} ' .format (NUM)) 
        h_limit = gus_age 
    NUM -. 1 =
     the while NUM == -1 : 
        Choice = iNPUT ( ' has 3 strikes, whether to continue, continue to enter "Y", to exit the input "Q": ' )
         iF Choice in [ ' the Y ' ,' Y ' ]: 
            NUM = 2
         elif Choice in [ ' Q ' , ' Q ' ]:
             BREAK 
        the else :
             Print ( ' input is not valid, please re-enter " )

 

Guess you like

Origin www.cnblogs.com/caoyu080202201/p/12449528.html