美文网首页
学Python的入门(2)——完成了自己的第一个小程序

学Python的入门(2)——完成了自己的第一个小程序

作者: rickd83 | 来源:发表于2017-09-29 11:04 被阅读0次

人类历史的一小步,我个人的一大步。

  import random



  def roll_dice(numbers=3,points=None):
      if points is None:
          points = []
      while numbers >0:
          point = random.randrange(1,7)
          points.append(point)
          numbers -= 1
      return points
    
  def roll_result(total):
      is_big =    11< total <19
      is_small = total < 12
      if is_big:
          return 'big'
      if is_small:
          return 'small'
    
    
    
  def verify(mobile):
      CN_mobile = [134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705]
      CN_union = [130,131,132,155,156,185,186,145,176,1709]
      CN_telecom = [133,153,180,181,189,177,1700]
      CN_mobile = list(map(str,CN_mobile))
      CN_union = list(map(str,CN_union))
      CN_telecom = list(map(str,CN_telecom))
      if len(mobile) == 11:
          if mobile[:3] in CN_mobile or mobile[:4] == '1705':
              return 'cn_mobile'
          elif mobile[:3] in CN_union or mobile[:4] == '1709':
              return 'cn_union'
          elif mobile[:3] in CN_telecom or mobile[:4] == '1700':
              return 'cn_telecom'
        else:
              return None
      else:
         return None

  def money(bonus,gumble):
      if int(bonus) >= int(gumble):
         return True
      else:
          return False




  def start_game():
          print('----game start----')
          bonus = 1000
          gamble_money = 0 
          guess = ['big','small']
    
          while True:
              mobile = input('Enter your mobile: ')
              mobile = str(mobile)
              judge = verify(mobile)
              if judge is not None:
                  print(verify(mobile))
                  break
              else:
                  print('Wrong Number')
                  verify(mobile)
            
          while bonus > 0:
              gamble_money = input('Enter your money: ')
              while True:
                  if money(bonus,gamble_money):
                      break
                  else:
                      print('Your input is more than your bonus')
                      gamble_money = input('Enter your money: ')
                      money(bonus,gamble_money)
            
              your_guess = input('Enter your guess: ')
              while True:
                  if your_guess in guess:
                      points = roll_dice()
                      total = sum(points)
                      if your_guess == roll_result(total):
                          print('WIN, The final is',points)
                          gamble_money = + int(gamble_money)
                      else:
                          print('LOST,The final is',points)
                          gamble_money = - int(gamble_money)
                      break
                  else:
                  print('Invalid guess')
                  your_guess = input('Enter your guess: ')
              bonus = bonus + gamble_money
              print('Your bonus now is ',bonus)
        
          print('You have no money,Game Over')

相关文章

网友评论

      本文标题:学Python的入门(2)——完成了自己的第一个小程序

      本文链接:https://www.haomeiwen.com/subject/zwxiextx.html