Guess the size (python)

table of Contents

 

Game 1:

Game two:

Supplement: ——Query account number (number)


Game 1:

Game : Roll the dice

Game rules : At the beginning of the game, the player chooses Big or Small, and then starts to roll three dice to calculate the total value. 11<= total <= 18 is big, 3<= total <= 10 is small, and then tell the player to guess right/guess wrong

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

Output:

<<<<< GAME STARTS! >>>>>
Big or SmallBig
<<<<< ROOL THE DICE!
The points are  [3, 5, 3] You win !

Game two:

Game : Roll the dice bet amount and odds

Game rules : the same size value as the appeal game

  • The initial amount is 1000
  • The game ends when the amount is 0
  • The default odds are doubled, betting on the right to get the corresponding amount, and losing the corresponding amount by mistake.
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()

Output:

<<<<< GAME STARTS! >>>>>
Big or Small:Big
How much you wanna bet?500
<<<<< ROOL THE DICE!
The points are  [6, 5, 1] You win !
You gained 500you have 1500now
Big or Small:Small
How much you wanna bet?1000
<<<<< ROOL THE DICE!
The points are  [4, 3, 4] You lose !
You lost 1000you have 500now
Big or Small:Big
How much you wanna bet?500
<<<<< ROOL THE DICE!
The points are  [3, 1, 4] You lose !
You lost 500you have 0now

Process finished with exit code 0
 

Encounter problems:

问题:TypeError: unsupported operand type(s) for +: 'int' and 'str'

: pay_money = int(input('How much you wanna bet?'))

Supplement: ——Query account number (number)

Rules: When registering the game, the mobile phone will be used as the account name, and the authenticity of the number will be verified before the SMS verification. If the number does not exist, the verification code will not be sent. The verification rules are as follows:

  • The length is not less than 11
  • It is a phone number in the number segment of China Mobile, China Unicom, and China Telecom
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()

Output :

Enter Your  number:135555555555555555
Operator : Chine Mobile
We ' re sending verification code via text to your phone 135555555555555555

Guess you like

Origin blog.csdn.net/qq_41070511/article/details/114919931