""" 购买1级石头 """ def l1cost(n): l1_value = 0.75 # 1颗1级石头消耗0.75金 l1_value_diamond = 8 #1颗1级石头同时还需要消耗8颗钻石 l1_cost = l1_value + l1_value_diamond * 0.05 return(l1_cost * n) """ 1级合成3级 """ def l3cost(n): l1_to_l3 = 12 #1颗1级石头变成1颗3级石头,需要消耗12颗1级石头 l1_to_l3_gold = 0.39 #同时还需要消耗0.39金 l1_to_l3_vit = 10 #同时还需要消耗10点体力 l1_to_l3_cost = l1cost(l1_to_l3) + l1_to_l3_gold + l1_to_l3_vit return(l1_to_l3_cost * n) """ 3级合成4级 """ def l4cost(n): l3_to_l4 = 16 #1颗3级石头变成1颗4级石头,需要消耗16颗1级石头 l3_to_l4_gold = 0.897 #1颗3级石头变成1颗4级石头,需要消耗0.897金 l3_to_l4_vit =10 #同时还需要消耗10点体力 l3_to_l4_rate = 0.4878 #1颗3级石头变成1颗4级石头,成功概率为0.4878 #如果失败,则金和16颗1级五行石也被扣除,但是不消耗体力 l3_to_l4_cost = l3cost(1) + (l1cost(l3_to_l4) + l3_to_l4_gold) / l3_to_l4_rate + l3_to_l4_vit return(l3_to_l4_cost * n) """ 4级合成6级 """ def l6cost(n): l4_to_l6 = 12 #1颗4级石头变成6级石头,概率为100%,需要消耗12颗4级石头 l4_to_16_gold = 19.75 #需要消耗19.75金 l4_to_16_vit = 10 #同时还需要消耗10点体力 l4_to_l6_cost = l4cost(l4_to_l6) + l4_to_16_gold + l4_to_16_vit return(l4_to_l6_cost * n) print("1个1级石头消耗:", l1cost(1) ,"金") print("1个3级石头消耗:", l3cost(1) ,"金") print("1个4级石头消耗:", l4cost(1) ,"金") print("1个6级石头消耗:", l6cost(1) ,"金") 运算结果是: 1个1级石头消耗: 1.15 金 1个3级石头消耗: 24.189999999999998 金 1个4级石头消耗: 73.7492455924559 金 1个6级石头消耗: 914.7409471094709 金 还有个问题,老师题目中说1颗1级石头变成1颗3级石头,需要消耗12颗1级石头,那么总共是消耗了12颗 还是13颗?