1. 程式人生 > >python搖骰子游戲

python搖骰子游戲

import random
def roll_dice (numbers = 3,points = None):
    print("<<<<<ROLL THE DICE!>>>>>")
    if points is None:
        points =[]
    while numbers > 0:
        points = random.randrange(1,7)
        points.append(points)
        numbers = numbers -1
    return points
 def roll_result(total):
     is_big = 11 <= total <= 18
    is_small = 3 <= total <= 10
    if is_big:
        return 'big'
    elif is_small:
        return 'small'
 def start_geme():
    print('<<<<<GAME STARTS!>>>>> ')
    choices = ['big','small']
    your_choice = input('big or small')
    if your_choice in choices:
        points =roll_dice()
        total = sum(points)
        youwin = your_choice == roll_result( total )
        if youwin:
            print('the points is',points,'you win!')
        else:
            print('the points is', points, 'you lose!')
    else:
        print('invalid word')
        start_geme()
start_geme()
 

 

 

大哥說這個在遊戲開發中,就是自動免除了編譯的那一塊,直接通過C++呼叫對應的PYTHON指令碼。而不用重新編譯。

我說那是不是就是AI人工智慧方面,自動學習就是自己會寫對應的PYTHON指令碼了?(還真有可能!)