zoukankan      html  css  js  c++  java
  • python摇骰子猜大小的小游戏

    #小游戏,摇筛子押大小的小游戏
    玩家初始有1000块钱,可以压大压小作为赌注 import random #定义摇筛子的函数: def roll_dice(number = 3,points = None): print ('<<<<< Roll The Dice >>>>>') if points is None: points = [] while number > 0: point = random.randrange(1,7) points.append(point) number = number - 1 return points #将点数转换为大小的函数: def roll_result(total): isBig = 11 <= total < 18 isSmall = 3 <= total < 10 if isBig: return 'isBig' elif isSmall: return 'isSmall' #开始游戏的函数;
    def start_game():
        you_money = 1000
        while you_money > 0:
            print ('<<<<< GAME START >>>>>')
            choices = ['isBig','isSmall']
            your_choices = input('isBig or isSmall:')
            if your_choices in choices:
                you_bet = int(input('How nuch you wana bet? :'))
                points = roll_dice()
                total = sum(points)
                youWin = your_choices == roll_result(total)
                if youWin:
                    you_money = you_money + you_bet
                    print('The points are', points, 'You win !')
                    print('You gained {},you have {} now'.format((you_bet,you_money)))
                else:
                    you_money = you_money - you_bet
                    print('The points are', points, 'You lose !')
                    print('You lost {},you have {} now'.format(you_bet,you_money))
            else:
                print('Invalid Words')
        else:
            print ('GAME IS OVER!')
    start_game()
    

      

      

  • 相关阅读:
    Jmeter运行badboy录制的脚本
    Bugfree安装与使用
    JMeter录制脚本
    第六天-linux系统优化初步讲解
    第五天-linux基础命令
    第四天-secureCRT-ssh客户端使用详解
    第三天-linux版本选择及安装
    第二天-计算机硬件基本知识和linux发展简史
    第一天-学习linux运维
    ubuntu15.04 无线上网问题
  • 原文地址:https://www.cnblogs.com/pythonal/p/6008834.html
Copyright © 2011-2022 走看看