防痴呆的:啤酒2元一瓶,四个瓶盖可换一瓶啤酒,2个空瓶也可换一瓶啤酒,10元最多可以喝多少瓶

来源:互联网 发布:武汉美工速成班 编辑:程序博客网 时间:2024/04/28 20:57
#!/usr/bin/env python2#-*- coding: utf-8 -*-def calculate_beer(money):    total_beer = 0    first_round_num = money / 2    total_beer = +first_round_num    bottle_num = first_round_num    cap_num = first_round_num    print("The total_beer = %d, bottle_num = %d,  cap_num is %d") %(total_beer, bottle_num, cap_num )    while((bottle_num >= 2) or (cap_num >= 4)):        exchange_bottle = bottle_num / 2        exchange_cap    = cap_num / 4        residual_bottle = bottle_num % 2        residual_cap = cap_num % 4        total_beer = total_beer + exchange_bottle + exchange_cap        bottle_num = residual_bottle + exchange_bottle + exchange_cap        cap_num = residual_cap + exchange_bottle + exchange_cap        print("The total_beer = %d, bottle_num = %d,  cap_num is %d") %(total_beer, bottle_num, cap_num )        #print(total_beer)    print("The calculate result is :")    print("The total_beer = %d, residual bottle_num = %d, residual cap_num is %d") %(total_beer, bottle_num, cap_num )calculate_beer(10)
0 0
原创粉丝点击