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

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

  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')
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 阴雨绵绵的天气 浓墨重彩的天空 云朵像被墨汁染过了一样 行走匆忙的旅人 踏着雨水的脚步 溅上水花的裤脚 鞋上的泥渍...
    blakelively阅读 262评论 1 0
  • 早上起来,大家都很高兴,昨天晚间洗漱时,响响看到我在用眼霜,她很喜欢,小女孩天性,我就把盖子给她玩,注意此处自己挖...
    响珊珊阅读 272评论 0 0
  • 在得到中我订阅了王烁大学问,其中讲了一个简单的经济模型: 假设潜在买房者有两种,一种看多,一种看空;房价只有一个价...
    丁昆朋阅读 734评论 0 2
  • 如果说相遇 是一出古老的戏 那你我就是戏里的青衣 水袖飘舞,摇曳轻曼 唱着缠绵幽怨的小曲 上演着人间离离合合的悲喜...
    汤河水阅读 447评论 7 7