Practice1 construction narcissistic number
"" " Constructor daffodils Version 0.1 author Luo Xu as " "" for X in Range ( 100 , 1000 ): A = int (X / 100 ) B = int (X% 100 / 10 ) C = int (X% 10 ) IF POW (A, . 3 ) + POW (B, . 3 ) + POW (C, . 3 ) == X: Print (X)
Practice 1*
"" " Configured from a power of Version 0.1 author Luo Xu as " "" Import Math # from a power of the number of bits n- n- = int (INPUT ( ' Enter maximum self-power-of-digits: ' )) for A in Range ( . 1 , n-+ . 1 ): #a is a power counter for I in Range (Math.pow ( 10 , A- . 1 ), POW ( 10 , a)): NUM = 0 #x is a natural number to be determined for J in STR (I): NUM + = int (Math.pow ((int(j),a) if i == num: print (i)
Practice 2 perfect number
"" " Constructor perfect all perfect of counting approximately and exactly equal to the figure itself, Version 0.1 author Luo Xu as " "" # for a perfect number less than n- Import Math n- = int (INPUT ( ' Query perfect number less than n, input n-: ' )) #n is the maximum query for x in Range ( . 1 , n-+ . 1 ): #x is being determined is a value NUM = 0 for K in Range ( . 1 , x): #k is true of about x number IF X% K == 0 : NUM + = K IF NUM == X: Print ( ' % D perfect number ' % X)
Practiice 3 one hundred white chicken money problems
"" " Chicken Weng a valuable five chicken mother a valuable three chicks three valuable a. One hundred to buy one hundred chicken ask chicken Weng, chicken mother, chicks each geometric verision 0.1 author Luo Xu as " "" # chicken Weng number g, chicken mother number m, chicks number of C for G in Range ( . 1 , 20 is ): for m in Range ( . 1 , 34 is ): for C in Range ( . 1 , 100 ): IF . 5 * G + . 3 * m + 0.3 * C == 100 and G m + C == + 100 : Print ( 'Weng only chicken% d,% d only female chickens, chicks only% d ' % (G, m, C))
Practice 4
"" " Configured Fibonacci numbers columns are defined in a recursive method: F. ( . 1 ) = . 1 , F. ( 2 ) = . 1 , F. (N-) = F. (N- . 1 ) + F. (N- 2 ) ( n-> = . 3 , n∈N * ) Version 0.1 author to Luo Xu "" " n-= int (INPUT ( ' the number of required output Fibonacci numbers: ' )) a, B = 0 , . 1 SUM = 0 for _ in Range ( . 1 , n-+ . 1 ): A, B = B, A + B Print (A, End = ' ')
Practice 5
"" " Rules of the game: the players throw two dice, each dice 1 - 6 , if the first points and 7 or 11, the player wins; if the number of points and is 2, 3 or 12, the player loses the dealer wins. If and to other points, the record number of points and the first, the players continue to roll the dice until the number of points and the number of points equal to the first throw and then the player wins; if to throw points and seven Zhuang Jiasheng. Version 0.1 author Luo Xu as "" " Import Random Money = 1000 the while Money> 0 : Print ( ' your assets ' , Money) needs_go_on = False the while True: a bET = int (the INPUT ( ' $$$ Place your bets: ' ) ) Money = Money - BET IF BET> 0 and Money> 0 : BREAK Point = the random.randint ( . 1 , . 6 ) the random.randint + ( . 1 , . 6 ) Print ( ' shake a point% d ' % Point) IF Point = = . 7 or Point == . 11 : Print ( ' the player wins ' ) Money + = 2 * BET elif Point == 2== Point or . 3 or Point == 12 is : Print ( ' Zhuangjia Sheng out ' ) the else : needs_go_on = True the while needs_go_on: P = the random.randint ( . 1 , . 6 ) the random.randint + ( . 1 , . 6 ) Print ( ' shake-out point of% d ' % P) IF P == point: Print ( ' the player wins ' ) Money + = 2 *a BET needs_go_on = False elif the p- == 7 : Print ( ' Zhuang Jiasheng out ' ) needs_go_on = False Print ( ' you went bankrupt, the end of the game! ' )