Python中文
首页
教程
问答
标签
搜索
登录
注册
python为什么我的变量没有改变并使用我的字典
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>所以我在做一个课堂作业,基本上我必须这样做,但是当我运行我的程序时,它不会从我的字典中提取数字来添加它们。当我把热饮放入输入项时,它不会将4.25添加到num1或任何其他项中</p> <pre><code>import time coffee = {"hot brew": 4.25, "latte": 4.75, "mocha": 4.99, "cold brew": 3.95, "cappuccino": 4.89, "dount": 1.50} num8 = 0 while num8 == 0: num7=0 while num7 == 0: items = input("what items would you like to buy or leave blank to end your order") num1=0 num2=0 num3=0 num4=0 num5=0 num6=0 total=0 if items == "hot brew": num1 = num1 + coffee["hot brew"] elif items == "latte": num2 = num2 + coffee["latte"] elif items == "mocha": num3 = num3 + coffee["mocha"] elif items == "cold brew": num4 = num4 + coffee["cold brew"] elif items == "cappuccino": num5 = num5 + coffee["cappuccino"] elif items == "dount": num6 = num6 + coffee["dount"] elif items == "": num7 = num7 + 1 else: print("that item does not exit") total = num1 + num2 + num3 + num4 + num5 + num6 total = total * 1.07 print ("your order is " + str(total) + "$") time.sleep(5) leave = input("would you like to close the program yes or no") if leave == "yes": num8 = 1 </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p><code>num1-num6</code>变量是循环中的<code>initialized</code>。因此,每次循环递增时,这些变量都得到<code>reassigned to zero</code>。您必须在<code>num7 == 0</code>循环之外定义它</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
2 回答
如何在python中从数据帧列表中删除引号
2 回答
如何在python中从数据帧创建列表
2 回答
如何在Python中从数据帧创建嵌套的JSON
3 回答
如何在Python中从数据帧显示wordcloud
1 回答
如何在Python中从数据帧的时间戳中删除字符
1 回答
如何在Python中从数据帧绘制简单绘图?
3 回答
如何在python中从数据帧行提取具有特定长度的范围?
10 回答
如何在python中从数据帧设置dict中的值
6 回答
如何在Python中从数据库中获得一个结果
8 回答
如何在python中从数据框中绘制分类条形图
4 回答
如何在Python中从数据框中选择特定细节?
4 回答
如何在python中从数据集中删除unicode
8 回答
如何在python中从数据集中删除某些数值?
3 回答
如何在python中从数据集中选择行
8 回答
如何在Python中从数组中删除元素
4 回答
如何在python中从数组中删除单个倒逗号?
6 回答
如何在python中从数组中删除对象?
5 回答
如何在python中从数组中删除引号
6 回答
如何在python中从数组中删除所有最小值
8 回答