请多指教!大学生计算机专业自学python

获取时间,具体时间年月日:

如果需要其他的时间 可以直接网上搬,不同的格式的都有 以及时间戳

猜筛子大小小游戏:

随机生成3个筛子,玩家来猜测3个筛子和的大小 (和3<=x<=10为小,11<=x<=18为大 )

import random

initial_money = 1000
current_money = initial_money

def roll_dice():
    #有3三个筛子
    dice1 = random.randrange(1,6)
    dice2 = random.randrange(1,6)
    dice3 = random.randrange(1,6)
    return dice1+dice2+dice3

def main():
    global current_money
    print('Welcome to the Big Small Game!')

    while current_money > 0:
        print(f'\nCurrent balance:${current_money:.2f}')
        #Get player bet amount
        while True:
            try:
                bet_amount = float(input('Enter your bet amount (Enter 0 to quit):'))
                if bet_amount < 0:
                    print('Please enter a non-negative bet amount.')
                elif bet_amount > current_money:
                    print("Insufficient balance. Please enter a smaller bet amount.")
                else:
                    break
            except ValueError:
                print("Invalid input. Please enter a valid number.")
        if bet_amount == 0 :
            print('Game over.thank you for playing !')
            break

        print("Choose 'big' or 'small' to bet on the sun of three dice.")
        player_chioce = input("Enter your chioce('big or small'): ").strip().lower()

        if player_chioce not in ['big','small']:
            print("Invalid choice. Please choose 'big' or 'small'.")
            continue

        total = roll_dice()
        print(f"The total value of three dice is: {total}")

        if (total >=11 and total <=18 and player_chioce == 'big') or (total >=3 and total <=10 and player_chioce =='small'):
            winnings = bet_amount
            current_money += winnings
            print(f"Congratulations! You guessed correctly and won ${winnings:.2f}!")

        else:
            winnings = -bet_amount
            current_money += winnings
            print(f"Sorry, you guessed incorrectly and lost ${winnings :.2f}.")

    else:
        print("You have run out of money. Game over!")

main()

 

文本过滤器:

def text_create(name, msg):
    desktop_path = 'D:/python练习/'
    full_path = desktop_path + name + '.txt'
    file = open(full_path, 'w')
    file.write(msg)
    file.close()
    print('Done')


text_create('hello', 'hello world')


def text_filter(word, censored_word='lame', changed_word='Awesome'):
    return word.replace(censored_word, changed_word)


text_filter('python is lame')


def censored_text_create(name, msg):
    clean_msg = text_filter(msg)
    text_create(name, clean_msg)


censored_text_create('Try', 'lame!lame!lame')

手机号码校验:

CN_mobile =[134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,148,1705]
CN_union =[130,131,132,155,156,185,186,145,176,1709]
CN_telecom =[133,153,180,181,189,177,1700]

def mian():
    Your_number = input("Enter your number:")
    # CN_CN = {
    #     "CN_mobile" : [134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 147, 148,1705],
    #     "CN_union" : [130, 131, 132, 155, 156, 185, 186, 145, 176, 1709],
    #     "CN_telecom" : [133, 153, 180, 181, 189, 177, 1700]
    # }
    #prefix取出输入的电话号码的前3位
    prefix = int(Your_number[:3])
    if len(Your_number) != 11:
        print("Invalid length,your number should be in 11 digits")
    # elif not any(prefix in segment for segment in CN_CN.values()):
    #通过prefix not in  判断输入的电话号码  属不属于上面的三个运营商
    elif prefix not in CN_mobile+CN_union+CN_telecom:
        print("No such an operator")
    else:
        if prefix in CN_union:
            print("Operator :China Union")
        elif prefix in CN_mobile:
            print("Operator :China mobile")
        elif prefix in CN_telecom:
            print("Operator :China telecom")
        print(f"We're sending verification code via text to your phone :{Your_number}")
mian()

python小白 请大家多指教 希望追赶上各位大佬 与大家共同进步!!!









评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值