一、题目描述
二、题目解答
import random
def redEnv(k, rest):
m = random.random() * rest
return m
total = float(input("请输入红包金额:"))
num = int(input("请输入红包个数:"))
remain = total
for i in range(num - 1):
money = redEnv(i, remain)
remain -= money
print("红包%d:%.2f" % (i + 1, money))
print("红包%d: %.2f" % (num, remain))
疑问
redEnv()函数的参数k如何理解?
测试用例
-
5块,1个红包:
-
10块,4个红包:
-
书中样例,36.5块,9个红包: