サイコロ投げ奇数偶数7時

3855 ワード

サイコロを投げるゲーム:初めて投げるとき、2点の和が偶数であれば、7より小さいときはプレイヤーが勝ち、7より大きいときは荘家が勝つ.2点の和が奇数であれば、勝負が決まるまで投げ続ける必要があります.このような煩雑な操作を賭ける必要はなく、簡単に1セットで勝負すればいい.
from random import randint
needs_go_on = True
while needs_go_on:
    current = randint(1,6)+randint(1,6)
    print('   %d '%current)
    if current%2==0:
        needs_go_on = False
        if current>7:
                print('   !')
        else:
                print('   !')

コメント機能の追加

#       

from random import randint
money = 100
while money>0:
    print('your asset is: ',money)
    needs_go_on = True
    while True:
        debt = int(input('   : '))
        if debt > 0 and debt <= money:
            break
        
    while needs_go_on:
        current = randint(1,6)+randint(1,6)
        print('   %d '%current)
        if current%2==0:
            needs_go_on = False
            if current>7:
                    print('   !')
                    money += debt
            else:
                    print('   !')
                    money -= debt

print('game over')

実行結果:
your asset is:  280
   : 200
   6 
   !
your asset is:  80
   : 80
   5 
   7 
   10 
   !
your asset is:  160
   : 160
   4 
   !
game over

このゲームは*に注意しなければならない.サイコロを投げるのは難しくない.主にneeds_を理解しなければならない.go_onがTrue or Falseのときの意味.