Python中文
首页
教程
问答
标签
搜索
登录
注册
Python While Statement with greater than/less than signs
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<pre><code>print ("Hello, this is a change return program, coded by A person") cost = float(input("How much did the object cose (in £s, eg 0.50 for 50p)?")) given = float(input("How much money did you pay (in the same format)?")) change = given - cost twentypounds = 0 tenpounds = 0 fivepounds = 0 twopounds = 0 onepound = 0 fiftypennies = 0 twentypennies = 0 tenpennies = 0 fivepennies = 0 twopennies = 0 onepenny = 0 print(change) while change >= 20: change = change - 20 twentypounds + 1 print(twentypounds) while change >=10 and <20 : change = change - 10 tenpounds + 1 print(tenpounds) while change 10> and >= 5: change = change - 5 fivepounds + 1 print(fivepounds) while change <5 and >= 2: change = change - 2 twopounds + 1 print(twopounds) while change <2 and >= 1: change = change - 1 onepound + 1 print(onepound) while change <1 and >= 0.5: change = change - 0.5 fiftypennies + 1 print(fiftypennies) while change <0.5 and >= 0.2: change = change - 0.2 twentypennies + 1 print(twentypennies) while change <0.2 and >= 0.1: change = change - 0.1 tenpennies + 1 print(tenpennies) while change <0.1 and >= 0.05: change = change - 0.05 fivepennies + 1 print(fivepennies) while change <0.05 and >= 0.02: change = change - 0.02 twopennies + 1 print(twopennies) while change <0.02 and >= 0.01: change = change - 0.01 onepennies + 1 print(onepenny) print("The Change Value is now:", change, " This is for debugging only") twenty_pounds = twentypounds * 20 ten_pounds = tenpounds * 10 five_pounds = fivepounds * 5 two_pounds = twopounds * 2 one_pound = onepound * 1 fifty_pennies = (fiftypennies * 50) / 100 twenty_pennies = (twentypennies * 20) / 100 ten_pennies = (tenpennies * 10) / 100 five_pennies = (fivepennies * 5) / 100 two_pennies = (twopennies * 2) / 100 one_penny = (onepenny * 1) / 100 total_change = twenty_pounds + ten_pounds + five_pounds + two_pounds + one_pound + fifty_pennies + twenty_pennies + ten_pennies + five_pennies + two_pennies + one_penny print("Your Total Change is:", total_change) </code></pre> <p>当它起作用时,它只返回0.0次,现在总是给我无效的语法,我尝试过交换符号,然后也交换数字,但是在任何情况下都没用,有什么办法解决这个问题吗?在</p> <hr/> <p>新代码:(仍然不工作,尽管现在没有语法错误,只返回0(尽管第4行的数字发生了变化)</p> ^{pr2}$ <p>现在代码只打印: (更改正确) 0.0,0.0,0.0等。。。在</p> <p>代码现在起作用了,谢谢你的回答!在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>==是一个比较 =是作业</p> <p>您在应该使用==的地方使用了==</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
当用户用PYTHON设置一个或一个不带值的URL时,他们怎么能输入一个/a的代码呢?
10 回答
当用户登录到站点时,如何显示不同的导航栏
8 回答
当用户登录时,在Flask中向用户显示处理结果
1 回答
当用户的Flask会话结束时,我如何从Redis后端中移除所有Celery结果?
8 回答
当用户的Okta配置文件字段当前为blan时,更新该字段
7 回答
当用户的付款逾期2天时,从Django模型检索数据
5 回答
当用户的消息以问号结尾时,如何让机器人说些什么?
1 回答
当用户的系统上可能也安装了Python 2.7时,如何在用户的系统上运行Python 3脚本?
4 回答
当用户确定打印数量时,使用Matplotlib打印动画
2 回答
当用户离开时是否可以删除整个网页?
7 回答
当用户给出一个单词时如何打印?
5 回答
当用户继续更改TKin中的值(使用trace方法)时,使用Entry并更新输入的条目
7 回答
当用户编辑表单字段时,从Django时间字段中删除秒数
3 回答
当用户被更改时,消息不会来自web套接字
3 回答
当用户访问表单时,如何使表单为只读,而不具有更改权限
2 回答
当用户试图更改对象的值时,使用描述符类引发RuntimeError
8 回答
当用户调整GUI的大小时,是否有方法更改GUI内容的大小?
1 回答
当用户调整风的大小时,pythontkinter小部件的大小会不均匀
7 回答
当用户购买某个类别时,是否查找其他类别的销售?
4 回答
当用户转到上一页时,Django和芹菜插入操作
6 回答