你好!下面是一个计算你过年获得的压岁钱的代码:

import random

def calculate_lucky_money(num_relatives):
    total_money = 0

    for _ in range(num_relatives):
        money = random.choice([20, 50, 100])
        num_children = random.randint(0, 3)
        
        money -= num_children * 50
        total_money += money

    return total_money

num_relatives = int(input("请输入今年一共拜访的亲戚数:"))
total_lucky_money = calculate_lucky_money(num_relatives)
print("我一共获得了 {} 元压岁钱".format(total_lucky_money))

希望对你有帮助!

写一个计算我过年获得的压岁钱的的代码亲戚随机给我面额20或50或100的压岁钱亲戚随机拥有0到3个小孩我需要给每个亲戚的每个小孩50元从我获得的压岁钱中我输入今年一共拜访的亲戚数计算我一共获得多少压岁钱

原文地址: https://www.cveoy.top/t/topic/iVMm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录