#Python 初学之二编写一个小游戏#

来源:互联网 发布:网络正规兼职写手 编辑:程序博客网 时间:2024/05/19 23:55
#密码输入三次错误输入限制                                                                password_list = ['####','12345']                                             def account_login():                                                             cishu = 3;                                                                   while cishu >0:                                                                     password = input ('password:');                                              password_correct = password ==password_list[-1];                             password_reset = password == password_list[0];                               if password_correct:                                                             print('login right!');                                                   elif password_reset:                                                             new_password = input('Enter a new password:');                               password_list.append(new_password);                                          print('your password has changed successfully!');                            account_login();                                                         else:                                                                            print('wrong login');                                                        cishu = cishu-1;                                                             print(cishu,'times left');                                        else:                                                                            print('Your account has ben suspended');                             account_login();                                                             output                                                                       password:34343434                                                            wrong login                                                                  2 times left                                                                 password:34334                                                               wrong login                                                                  1 times left                                                                 password:34334                                                               wrong login                                                                  0 times left                                                                 Your account has ben suspended                                               Process finished with exit code 0                                            #Python 编写一个小游戏!                                                             import random;                                                               def roll_dice(numbers=3,points=None):     #随机的三个数                                print('<<<<<<<<<<<<<<<<ROLL THE DICE!>>>>>>>>>>>>>>>');                      if points is None:                                                               points = [];                                                             while numbers >0:                                                                point = random.randrange(1,7);                                               points.append(point);                                                        numbers-=1;                                                              return  points;                                                          def roll_result(total):                                                          isBig   =  11<= total <= 18;                                                 isSmall =  3 <= total <= 10;                                                 if isBig:                                                                        return 'Big';                                                            elif isSmall:                                                                    return 'Small';                                                      def  start_gamw():                                                                print('<<<<<<<<<<<<<<<<GAME STARTS!>>>>>>>>>>>>>>>>>');                      choices = ['Big','Small'];                                                   your_choices = input('Big or Small:');                                       if your_choices in choices:                                                      points = roll_dice();                                                        total = sum(points);                                                         youWin = your_choices == roll_result(total);                                 if youWin:                                                                       print('The points are',points,'You win');                                    start_gamw();                                                            else:                                                                            print('The points are',points,'You lose!');                                  start_gamw();                                                        else:                                                                            print('Invalid Words');                                                      start_gamw();                                                       start_gamw();                                                                
0 0
原创粉丝点击