T恤单价为245元
运动鞋为370元
网球拍为345.5元
商场满两件打8折优惠,此次购物共拥有1500元
接下来实现代码
def main():
T_shirt_money = 245
sport_shoes_money = 370
tennis_money = 345.5
T_shirt_num = int(input('what T_shirt customer get many ?'))
sport_shoes_num = int(input('what sport_shoes customer get many ?'))
tennis_num = int(input('what tennis customer get many ?'))
if (T_shirt_num + sport_shoes_num + tennis_num) >= 2 :
how_much = T_shirt_num * int(T_shirt_money) + sport_shoes_num * int(sport_shoes_money)+ tennis_num * int(tennis_money)
end_money = int(how_much * 0.8)
print('\t\t\t\t\t\t\t********消费单********\t\t\n\t\t\t\t\t\t购买物品\t单价\t个数\t金额\n\t\t\t\t\t\tT恤\t\t${}\t{}\t${}\n\t\t\t\t\t\t网球鞋\t\t${}\t{}\t${}\n\t\t\t\t\t\t网球拍\t\t${}\t{}\t${}\n\n\t\t\t\t\t\t折扣:\t8折\n\t\t\t\t\t\t消费总金额\t${}\t实际缴费 ${}\n\t\t\t\t\t\t找零\t${}'
.format(int(T_shirt_money),T_shirt_num,T_shirt_num * int(T_shirt_money),
int(sport_shoes_money),sport_shoes_num,sport_shoes_num * int(sport_shoes_money),
int(tennis_money),tennis_num,tennis_num * int(tennis_money),end_money,1500,1500 - end_money))
else:
how_much = T_shirt_num * int(T_shirt_money) + sport_shoes_num * int(sport_shoes_money)+ tennis_num * int(tennis_money)
print('\t\t\t\t\t\t\t********消费单********\t\t\n\t\t\t\t\t\t购买物品\t单价\t个数\t金额\n\t\t\t\t\t\tT恤\t\t${}\t{}\t${}\n\t\t\t\t\t\t网球鞋\t\t${}\t{}\t${}\n\t\t\t\t\t\t网球拍\t\t${}\t{}\t${}\n\n\t\t\t\t\t\t消费总金额\t${}\t实际缴费 ${}\n\t\t\t\t\t\t找零\t${}'
.format(int(T_shirt_money),T_shirt_num,T_shirt_num * int(T_shirt_money),
int(sport_shoes_money),sport_shoes_num,sport_shoes_num * int(sport_shoes_money),
int(tennis_money),tennis_num,tennis_num * int(tennis_money),how_much,1500,1500 - how_much))
if __name__ == '__main__':
main()
写一篇简单的小票实现过程
接下来验证小票是否能够正确打印数据
分别实现了:
1.一件T恤,1双球鞋,一只网球拍,最后打印数据
2.0件T恤,1双球鞋,0只网球拍,最后打印数据