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()

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM