我正在嘗試創建一個更改返回程序,該程序需要一個項目的成本和給定的資金,並返回筆記,宿舍,硬幣等方面的適當更改。等在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())' –