zoukankan      html  css  js  c++  java
  • [Python学习之路] 猜大小游戏

     1 # coding =utf-8
     2 import random
     3 
     4 def roll_dice(number=3, points=None):
     5     if points == None:
     6         points = []
     7     while number > 0:
     8         point = random.randrange(1,7)
     9         points.append(point)
    10         number = number - 1
    11 
    12     return points
    13 
    14 
    15 def roll_result(total):
    16     print('<<<<< ROLL THE DICE! >>>>>')
    17     if 3 < total <10 :
    18         return 'Small'
    19     else:
    20         return 'Big'
    21 
    22 def start_game():
    23     Money = 1000
    24     while Money > 0:
    25         print('<<<<< GAME STAR! >>>>>')
    26         print('You have',Money,'now')
    27 
    28         you_bet = int(input('How much you wanna bet ? -'))
    29         judge = you_bet > Money     #判断赌金是否超过本金
    30         while judge:
    31             print('You have not enough money,enter again :')
    32             you_bet = int(input('How much you wanna bet ? -'))
    33             judge = you_bet > Money
    34 
    35         choices =['Big', 'Small']
    36         your_choice = input('Big or Small :')
    37 
    38         if your_choice in choices:
    39             poins = roll_dice()
    40             total = sum(poins)
    41             result = roll_result(total)
    42             youWin = your_choice == result
    43             if youWin:
    44                 Money = Money +you_bet
    45                 print('YOU WIN! the point are ' , poins,'you get',you_bet)
    46 
    47             else :
    48                 Money = Money - you_bet
    49                 print('YOU LOSE! the point are ' , poins,'you lose',you_bet)
    50 
    51         else :
    52             print('Invalid words')
    53             start_game()
    54     print('<<<<<GAME OVER! >>>>>')
    55 
    56 start_game()
  • 相关阅读:
    ....
    排序相关的问题(jq,java)_1123
    Spring aop 记录操作日志
    vue -element ui 自定义验证规则,封装在公共的文件里
    vue
    ES6 新特性
    正则表达式
    面向对象基础--继承(2)
    面向对象基础(1)
    安装vue环境
  • 原文地址:https://www.cnblogs.com/liangjiahao713/p/6379985.html
Copyright © 2011-2022 走看看