空间站建造阶段,北京网站建设 乐云seo,用wordpress修改网站,长沙企业网站建设公司菜市场价格对比工具下面是一个基于Python的菜市场价格对比工具#xff0c;利用创新思维到创业实践课程中的理念#xff0c;帮助用户找到性价比最高的购买地点。import randomimport timeimport mathfrom datetime import datetimeimport matplotlib.pyplot as pltfrom pretty…菜市场价格对比工具下面是一个基于Python的菜市场价格对比工具利用创新思维到创业实践课程中的理念帮助用户找到性价比最高的购买地点。import randomimport timeimport mathfrom datetime import datetimeimport matplotlib.pyplot as pltfrom prettytable import PrettyTableclass MarketPriceComparator:def __init__(self):# 模拟菜市场数据名称、位置坐标、基础价格系数self.markets [{id: 1, name: 中心农贸市场, location: (40.7128, -74.0060), price_factor: 1.0, distance_factor: 1.0},{id: 2, name: 东城生鲜市场, location: (40.7214, -73.9882), price_factor: 0.95, distance_factor: 1.2},{id: 3, name: 西郊蔬菜批发市场, location: (40.7020, -74.0120), price_factor: 0.85, distance_factor: 1.5},{id: 4, name: 南门街市集, location: (40.7085, -74.0010), price_factor: 1.1, distance_factor: 0.8},{id: 5, name: 北苑综合市场, location: (40.7250, -74.0150), price_factor: 0.98, distance_factor: 1.3}]# 模拟商品价格数据库基础价格单位元/斤self.product_prices {蔬菜类: {西红柿: 3.5, 黄瓜: 2.8, 土豆: 1.5, 白菜: 1.2, 菠菜: 4.0,茄子: 3.2, 青椒: 3.8, 豆角: 4.5, 胡萝卜: 2.0, 西兰花: 5.0,芹菜: 2.5, 韭菜: 3.0, 洋葱: 1.8, 南瓜: 2.2, 冬瓜: 1.0},肉类: {猪肉: 18.0, 牛肉: 35.0, 羊肉: 38.0, 鸡肉: 12.0, 鸭肉: 15.0,鸡蛋: 5.5, 排骨: 22.0, 五花肉: 20.0, 牛腩: 36.0, 鸡腿: 10.0},水产类: {鲤鱼: 9.0, 草鱼: 10.0, 鲫鱼: 12.0, 虾: 35.0, 螃蟹: 45.0,带鱼: 18.0, 黄鱼: 25.0, 鱿鱼: 20.0, 扇贝: 30.0, 生蚝: 28.0}}# 用户位置模拟为纽约市中心self.user_location (40.7128, -74.0060)def calculate_distance(self, loc1, loc2):计算两个地理位置之间的距离简化版lat1, lon1 loc1lat2, lon2 loc2# 简化的球面距离计算实际应使用Haversine公式return math.sqrt((lat2-lat1)**2 (lon2-lon1)**2) * 100def get_real_time_price(self, product, market):获取实时价格模拟价格波动base_price self.product_prices.get(product, {}).get(product, None)if base_price is None:return None# 模拟价格波动±15%fluctuation random.uniform(-0.15, 0.15)price base_price * (1 fluctuation) * market[price_factor]# 模拟质量差异±5%quality_factor random.uniform(0.95, 1.05)price * quality_factorreturn round(price, 2)def find_nearby_markets(self, n3):查找附近的菜市场markets_with_distance []for market in self.markets:distance self.calculate_distance(self.user_location, market[location])adjusted_distance distance * market[distance_factor]markets_with_distance.append({market: market,distance: round(adjusted_distance, 1)})# 按距离排序markets_with_distance.sort(keylambda x: x[distance])return markets_with_distance[:n]def compare_prices(self, product_name):比较指定产品的价格nearby_markets self.find_nearby_markets(3)results []for item in nearby_markets:market item[market]distance item[distance]price self.get_real_time_price(product_name, market)if price is None:continue# 计算性价比指数价格越低距离越近指数越高value_index (1 / price) * (1 / distance) * 10000results.append({market_id: market[id],market_name: market[name],distance: distance,price: price,value_index: round(value_index, 2)})# 按性价比排序results.sort(keylambda x: x[value_index], reverseTrue)return resultsdef recommend_best_market(self, product_name):推荐最佳购买地点comparisons self.compare_prices(product_name)if not comparisons:return None, 未找到该产品或相关市场best_market comparisons[0]return best_market, comparisonsdef visualize_comparison(self, product_name, comparison_data):可视化价格比较if not comparison_data:print(无数据可展示)returnmarket_names [item[market_name] for item in comparison_data]prices [item[price] for item in comparison_data]distances [item[distance] for item in comparison_data]values [item[value_index] for item in comparison_data]fig, ax1 plt.subplots(figsize(10, 6))# 价格柱状图bars ax1.bar(market_names, prices, colorskyblue, alpha0.7)ax1.set_xlabel(菜市场)ax1.set_ylabel(价格 (元/斤), colorskyblue)ax1.tick_params(axisy, labelcolorskyblue)# 添加价格标签for bar in bars:height bar.get_height()ax1.annotate(f{height:.2f},xy(bar.get_x() bar.get_width() / 2, height),xytext(0, 3), # 3 points vertical offsettextcoordsoffset points,hacenter, vabottom)# 距离折线图ax2 ax1.twinx()ax2.plot(market_names, distances, ro-, linewidth2, markersize8, label距离(km))ax2.set_ylabel(距离 (km), colorred)ax2.tick_params(axisy, labelcolorred)# 性价比折线图ax3 ax1.twinx()ax3.spines[right].set_position((outward, 60))ax3.plot(market_names, values, g^-, linewidth2, markersize8, label性价比指数)ax3.set_ylabel(性价比指数, colorgreen)ax3.tick_params(axisy, labelcolorgreen)plt.title(f{product_name} 价格比较 - {datetime.now().strftime(%Y-%m-%d %H:%M)})fig.tight_layout()plt.savefig(f{product_name}_价格比较.png)plt.close()print(f已生成可视化图表: {product_name}_价格比较.png)def run(self):运行主程序print(\n *50)print(欢迎使用菜市场价格对比工具)print(*50)print(本工具帮助您比较周边菜市场价格找到性价比最高的购买地点)print(数据更新于:, datetime.now().strftime(%Y-%m-%d %H:%M))print(*50)while True:print(\n请选择操作:)print(1. 查询产品价格)print(2. 查看所有产品类别)print(3. 退出程序)choice input(请输入选项编号: )if choice 1:product_category input(\n请选择产品类别 (1-蔬菜类, 2-肉类, 3-水产类): )categories {1: 蔬菜类, 2: 肉类, 3: 水产类}if product_category not in categories:print(无效的选择请重新输入)continuecategory categories[product_category]print(f\n{category}包含以下产品:)for i, product in enumerate(self.product_prices[category], 1):print(f{i}. {product})product_choice input(\n请输入产品编号或名称: )try:# 尝试按编号选择idx int(product_choice) - 1if 0 idx len(self.product_prices[category]):product_name list(self.product_prices[category].keys())[idx]else:product_name product_choiceexcept ValueError:# 按名称选择product_name product_choice# 检查产品是否存在if category in self.product_prices and product_name in self.product_prices[category]:print(f\n正在查询 {product_name} 的价格...)time.sleep(1) # 模拟网络延迟best_market, all_markets self.recommend_best_market(product_name)if best_market:print(\n *50)print(f产品: {product_name} ({category}))print(*50)# 使用PrettyTable展示结果table PrettyTable()table.field_names [排名, 菜市场, 距离(km), 价格(元/斤), 性价比指数]for i, market in enumerate(all_markets, 1):table.add_row([i,market[market_name],market[distance],market[price],market[value_index]])print(table)print(\n推荐购买地点:)print(f★ {best_market[market_name]} ★)print(f距离: {best_market[distance]} km)print(f价格: {best_market[price]} 元/斤)print(f性价比指数: {best_market[value_index]})# 可视化展示self.visualize_comparison(product_name, all_markets)# 额外建议if best_market[distance] 2:print(\n小贴士: 该市场稍远但性价比高适合批量采购)elif best_market[price] 15:print(\n小贴士: 该产品质量较好适合对品质要求高的消费者)else:print(\n小贴士: 该市场价格实惠适合日常购买)else:print(all_markets) # 错误信息else:print(f抱歉未找到产品 {product_name}请检查拼写)elif choice 2:print(\n所有产品类别及示例:)for category, products in self.product_prices.items():print(f\n{category}:)for product in list(products.keys())[:5]: # 只显示前5个print(f - {product})if len(products) 5:print(f 等共{len(products)}种产品)elif choice 3:print(\n感谢使用菜市场价格对比工具祝您购物愉快)breakelse:print(无效的选项请重新输入)input(\n按Enter键继续...)if __name__ __main__:comparator MarketPriceComparator()comparator.run()创新点与创业实践元素创新思维应用1. 用户中心设计针对家庭主妇和老年人设计简单易用的界面2. 数据可视化通过图表直观展示价格比较结果3. 动态定价模型模拟真实市场价格波动±15%4. 性价比算法综合考虑价格、距离和质量因素5. 场景化建议根据用户选择提供实用购物建议创业实践元素1. 最小化可行产品(MVP)核心功能完整可快速迭代2. 商业模式思考- 免费基础服务吸引用户- 高级功能收费如历史价格追踪、个性化推荐- 与菜市场合作推广3. 市场验证模拟真实用户场景测试4. 竞争分析相比传统比价工具增加地理因素和性价比评估5. 增长策略通过口碑传播和用户推荐机制扩大用户群使用说明1. 运行程序后选择操作- 选项1查询特定产品价格- 选项2查看所有产品类别- 选项3退出程序2. 查询产品时- 先选择产品类别蔬菜/肉类/水产- 输入产品编号或名称- 程序将显示周边3个市场的价格、距离和性价比- 推荐性价比最高的购买地点- 生成可视化图表保存为图片文件3. 程序会模拟实时价格波动每次查询结果可能略有不同扩展思路1. 接入真实API获取市场价格数据2. 添加用户账户系统保存偏好3. 实现价格历史趋势分析4. 增加社区分享功能用户上报价格5. 开发移动端APP版本6. 添加促销活动提醒功能这个工具体现了创新思维中的用户中心设计和数据驱动决策同时融入了创业实践中的MVP开发和商业模式思考为菜市场购物提供了智能化解决方案。我是编程小白请大家多多指教谢谢