サイズを推測する(python)

目次

 

ゲーム1:

ゲーム2:

補足:-クエリアカウント番号(番号)


ゲーム1:

ゲーム:サイコロを振る

ゲームのルールゲームの開始時に、プレーヤーは大または小を選択し、次に3つのサイコロを振って合計値を計算し始めます。11<=合計<= 18が大きい、3 <=合計<= 10が小さい、次に、プレーヤーに正しいと推測する/間違って推測するように指示します

import random

def roll_dice(numbers = 3, points = None):
    print('<<<<< ROOL THE DICE!')
    if points is None:
        points = []
    while numbers > 0:
        point = random.randrange(1, 7)
        points.append(point)
        numbers = numbers - 1
    return points

def roll_result(total):
    isBig = 11 <= total <= 18
    isSmall = 3 <= total <= 10
    if isBig:
        return 'Big'
    elif isSmall:
        return 'Small'


def start_game():
    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 are ', points, 'You win !')
        else:
            print('The points are ', points, 'You lose !')
    else:
        print('Invalid Words')
        start_game()

start_game()

出力:

<<<<<ゲームが始まります!>>>>>
BigまたはSmallBig <<<<<
ROOL THE DICE!
ポイントは【3、5、3】勝ちです!

ゲーム2:

ゲーム:サイコロの賭けの金額とオッズをロールします

ゲームルール:アピールゲームと同じサイズ値

  • 初期金額は1000です
  • 金額が0になるとゲームは終了します
  • デフォルトのオッズは2倍になり、対応する金額を取得するために右側に賭け、誤って対応する金額を失います。
import random

def roll_dice(numbers = 3, points = None):
    print('<<<<< ROOL THE DICE!')
    if points is None:
        points = []
    while numbers > 0:
        point = random.randrange(1, 7)
        points.append(point)
        numbers = numbers - 1
    return points

def roll_result(total):
    isBig = 11 <= total <= 18
    isSmall = 3 <= total <= 10
    if isBig:
        return 'Big'
    elif isSmall:
        return 'Small'


def start_game():
    print('<<<<< GAME STARTS! >>>>>')
    choices = ['Big', 'Small']
    money = 1000
    while money > 0:
        your_choice = input('Big or Small:')
        pay_money = int(input('How much you wanna bet?'))
        if your_choice in choices:
            points = roll_dice()
            total = sum(points)
            youWin = your_choice == roll_result(total)
            if youWin:
                money = money + pay_money
                print('The points are ', points, 'You win !')
                print('You gained ' + str(pay_money) + 'you have ' + str(money) + 'now')
            else:
                money = money - pay_money
                print('The points are ', points, 'You lose !')
                print('You lost '+ str(pay_money) +  'you have ' + str(money) + 'now' )
        else:
            print('Invalid Words')
            start_game()


start_game()

出力:

<<<<<ゲームが始まります!>>>>>
大きいか小さいか:大きい
どれだけ賭けたいですか?500
<<<<< ROOL THE DICE!
ポイントは【6、5、1】勝ちです!
あなたは500を獲得しましたあなたは1500を持っています今
大小:小あなたはいくら
賭けたいですか?1000
<<<<< ROOL THE DICE!
ポイントは【4、3、4】負け!
あなたは1000を失いましたあなたは500を持っています今
大小:大あなたはいくら
賭けたいですか?500
<<<<< ROOL THE DICE!
ポイントは【3、1、4】負け!
あなたは500を失いましたあなたは今0を持っています

プロセスは終了コード0で終了しました
 

遭遇問題:

问题:TypeError:+のサポートされていないオペランドタイプ: 'int'および 'str'

回答:pay_money = int(input( 'いくら賭けたいですか?'))

補足:-クエリアカウント番号(番号)

規則:ゲームの登録時に、携帯電話がアカウント名として使用され、SMS検証の前に番号の信憑性が検証されます。番号が存在しない場合、検証コードは送信されません。検証規則以下の通り:

  • 長さは11以上
  • チャイナモバイル、チャイナユニコム、チャイナテレコムの番号セグメントの電話番号です。
def phone():
    CN_mobile = \
    [134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 147, 178, 1705 ]

    CN_union = [130, 131, 132, 155, 156, 185, 186, 145, 176, 1709]
    CN_telecom = [133, 153, 180, 181, 189, 177, 17700]

    your_number = input('Enter Your  number:')

    first_three = int(your_number[0:3])
    first_four = int(your_number[0:4])
    if len(your_number) >= 11:
        if first_three in CN_mobile or first_four in CN_mobile:
            print('Operator : Chine Mobile')
            print('We \' re sending verification code via text to your phone', your_number)
        elif first_three in CN_union or first_four in CN_union:
            print('Operator : Chine Union')
            print('We \' re sending verification code via text to your phone', your_number)
        elif first_three in CN_telecom or first_four in CN_telecom:
            print('Operator : Chine Telecom')
            print('We \' re sending verification code via text to your phone', your_number)

    else:
        print("Invalid length, your number shoule be in 11 digits")
        phone()

phone()

出力

あなたの番号を入力してください:135555555555555555
オペレーター:ChineMobile
私たちはあなたの電話にテキストで確認コードを送ります135555555555555555

おすすめ

転載: blog.csdn.net/qq_41070511/article/details/114919931