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)

当它工作时,它只返回0.0次多次,现在一直给我无效的语法,我试图交换标志,然后还有数字,但是无法解决任何问题,任何想法如何解决这个问题?

新代码:(仍然没有工作,虽然现在没有语法错误,只返回0(尽管数字在第4行有所变化)

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 change < 20:

change = change - 10

tenpounds + 1

print(tenpounds)

while change > 10 and change >= 5:

change = change - 5

fivepounds + 1

print(fivepounds)

while change < 5 and change >= 2:

change = change - 2

twopounds + 1

print(twopounds)

while change < 2 and change >= 1:

change = change - 1

onepound + 1

print(onepound)

while change < 1 and change >= 0.5:

change = change - 0.5

fiftypennies + 1

print(fiftypennies)

while change < 0.5 and change >= 0.2:

change = change - 0.2

twentypennies + 1

print(twentypennies)

while change < 0.2 and change >= 0.1:

change = change - 0.1

tenpennies + 1

print(tenpennies)

while change < 0.1 and change >= 0.05:

change = change - 0.05

fivepennies + 1

print(fivepennies)

while change < 0.05 and change >= 0.02:

change = change - 0.02

twopennies + 1

print(twopennies)

while change < 0.02 and change >= 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)

现在代码只打印:(更改是正确的)0.0,0.0,0.0等...

代码现在有效,感谢您的回答!

python中大于多少小于怎么表示_Python While语句大于/小于符号相关推荐

  1. python中else是指什么意思_python中elif什么意思?

    原标题:python中elif什么意思? else和elif语句也可以叫做子句,因为它们不能独立使用,两者都是出现在if.for.while语句内部的.else子句可以增加一种选择:而elif 子句则 ...

  2. python中demo函数是什么意思_Python学习09:定义函数

    这次我们在上一次创建的com.second.function下创建Demo02.py 在Python中,定义一个函数要使用 def 语句,依次使用函数名.括号.括号中的参数和冒号 : ,然后在缩进块中 ...

  3. python中的pass是空语句一般用作占位语句_1、python基本语法

    1.python基本语法 1.1. pycharm中字符集,单行,多行注释 #-*- codeing = utf-8 -*- [email protected] : 2020/6/6 15:17 [e ...

  4. python中用于获取当前目录的是_python中获得当前目录和上级目录的实现方法

    python中获得当前目录和上级目录的实现方法 获取当前文件的路径: from os import path d = path.dirname(__file__) #返回当前文件所在的目录 # __f ...

  5. python中find函数运算结果类型_Python 运算符与数据类型

    Python 运算符 运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算,在Python中运算符大致可以分为7种类型:算术运算符.比较运算符.赋值运算符.逻辑运算符.位运算等,下面的例子将 ...

  6. python中的ture是常量吗_python中的true是什么

    Python的布尔类型有两个值:True和False(注意大小写要区分,首字母大写,注意) 0.逻辑运算符:a.与:and(两个都为True,结果才为True) b.或:or(只要一个为True,则为 ...

  7. python中属于有序序列的有_Python中的有序序列有哪些

    Python中的有序序列有哪些 list.tuple以及str都是有序序列,和后面两者不同的是list是个可变对象,tuple和str则是不可变对象.主要讲的就是这三种的有序序列的一些方式.方法效果L ...

  8. python中的选择最高的成绩_python 输入学生成绩 若成绩在90、流程图_Python习题选编...

    <Python习题选编>由会员分享,可在线阅读,更多相关<Python习题选编(20页珍藏版)>请在人人文库网上搜索. 1.Python习题选编华东师大信息学院计算中心一程序结 ...

  9. python中if有多个条件_Python中if有多个条件处理方法

    Python中if有多个条件处理方法 Python中if有多个条件怎么办 python中if有多个条件,可以使用and.or.elif关键字来连接. Python 编程中 if 语句用于控制程序的执行 ...

  10. python中math.ceil是什么意思_python中的数字取整(ceil,floor,round)概念和用法

    python中的数学运算函数(ceil,floor,round)的主要任务是截掉小数以后的位数.总体来说 就是取整用的.只是三者之间有微妙的区别: floor() :把数字变小 ceil() : 把数 ...

最新文章

  1. python切片语法-Python切片详解
  2. android中layout、drawable及styles的xml文件加载探索
  3. Hive的基本操作-数据库的创建和删除
  4. Remoting实例(同为客户端服务端)
  5. python print格式化输出类型_第一讲:Python print() 格式化输出
  6. CSharpGL(7)对VAO和VBO的封装
  7. python opencv_Python open()
  8. iOS category解析
  9. 【docker】python: can't open file 'helloworld.py': [Errno 13] Permission denied
  10. 【软考】专栏导读(软考全面介绍、资格报考建议)
  11. 服务器安装版u盘如何制作,U盘怎么安装原版Windows server 2016?
  12. 【redis】docker启动redis,redis常用命令
  13. 转回到Edison上开发
  14. 计算机自杀式软件--USBKill
  15. cisco 防火墙模拟器_37、如果手头有华为AP,怎们配合模拟器做部分实验呢?(完结篇)...
  16. SFuzz: Slice-based Fuzzing for Real-Time Operating Systems
  17. unity 捕鱼达人鱼群的移动
  18. 【记录】oracle异常ORA-00205:????
  19. 【计算机网络】分组交换和电路交换
  20. 付宇泽20190919-4 单元测试,结对

热门文章

  1. 【无代码爬虫】web scraper 之 采集单个内容
  2. See Electrical 7 R2 B11电气设计软件PLS-CADD v12.3架空电力线设计软件
  3. iOS AddressBook
  4. 校园APP开发的优势和特点
  5. 区块链组适应不断变化的监管环境
  6. [MOT学习笔记]JDE损失函数详解
  7. 淘宝粉丝能买吗?怎么加最快
  8. flappy bird用java实现_java实现Flappy Bird游戏源代码
  9. maven中使用assembly打包
  10. 异度之刃2 任务打杂店的帮手去哪获取纯洁石