超市算找零

#include<stdio.h>
int main()
{
	int price=0;
	printf("请输入金额(元);");
	scanf("%d",&price);
	
	int change=100-price;
	printf("找您%d元。\n",change);
	return 0; 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来为您介绍一下Python超市收银统计和找零程序。 1. 超市收银统计程序 超市收银统计程序可以统计每个顾客的购买信息,包括商品名称、数量、单价、总价等,并且可以计所有顾客的购买总金额和商品销售排行榜等。 以下是一个超市收银统计程序的代码示例: ``` class Product: def __init__(self, name, price): self.name = name self.price = price self.total_quantity = 0 self.total_sales = 0 def add(self, quantity): self.total_quantity += quantity self.total_sales += quantity * self.price def get_sales(self): return self.total_sales def print_ranking(self, rank): print("第%s名:%s,销售额:%s" % (rank, self.name, self.total_sales)) class Customer: def __init__(self, id): self.id = id self.products = {} self.total_price = 0 def add_product(self, product, quantity): if product.name in self.products: self.products[product.name] += quantity else: self.products[product.name] = quantity self.total_price += product.price * quantity def print_receipt(self): print("顾客%s的购物清单:" % self.id) for name, quantity in self.products.items(): price = products[name].price total = price * quantity print("%s:%s * %s = %s" % (name, price, quantity, total)) print("总价:%s" % self.total_price) products = { "牛奶": Product("牛奶", 5.0), "面包": Product("面包", 3.0), "饼干": Product("饼干", 2.0) } customers = [] for i in range(3): customer = Customer(i + 1) for name, product in products.items(): product.add(i + 1) customer.add_product(product, i + 1) customers.append(customer) total_sales = 0 for name, product in products.items(): total_sales += product.get_sales() sorted_products = sorted(products.values(), key=lambda x: x.get_sales(), reverse=True) print("商品销售排行榜:") for i, product in enumerate(sorted_products): product.print_ranking(i + 1) print("总销售额:%s" % total_sales) for customer in customers: customer.print_receipt() ``` 2. 超市找零程序 超市找零程序可以根据顾客的支付金额和商品的总价计出应找的零钱,并且可以通过尽量减少硬币数量的方式来给出找零结果。 以下是一个超市找零程序的代码示例: ``` def calculate_change(total_price, paid): change = paid - total_price coins = [1, 2, 5, 10, 20, 50, 100] coins_count = {coin: 0 for coin in coins} while change > 0: for coin in reversed(coins): if change >= coin: coins_count[coin] += 1 change -= coin break return coins_count total_price = 15.5 paid = 20.0 change = calculate_change(total_price, paid) print("找零:") for coin, count in change.items(): if count > 0: print("%s元硬币:%s个" % (coin, count)) ``` 以上是Python超市收银统计和找零程序的代码示例,希望对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值