我正在尝试创建一个更改返回程序,该程序需要一个项目的成本和给定的资金,并返回笔记,宿舍,硬币等方面的适当更改。等在Python中将用户提供的数字转换为整数和浮点数
我是相当新的编程,我坚持试图分裂它。我查看了StackOverflow,发现方法math.modf(x)
是相关的。但是,我很难实施它。
能否请你让我知道为什么change
和y
is not defined
?
感谢
import math
def changereturn():
quarter = 0.25
dime = 0.1
nickel = 0.05
penny = 0.01
cost = float(raw_input('Please enter the cost of the item in USD: '))
money = float(raw_input('Please enter the amount of money given in USD: '))
change = money - cost
y = math.modf(change)
return change
return y
谢谢。我如何将整数部分赋值给一个变量,将浮点部分赋值给另一个变量?谢谢 – paulnsn
用我的'change,y = changereturn()'替换他的'print(changereturn())' –