Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:以10为基数的int()的文本无效:';0.50';(我无法理解这方面的其他帖子)_Python_Python 3.x - Fatal编程技术网

Python ValueError:以10为基数的int()的文本无效:';0.50';(我无法理解这方面的其他帖子)

Python ValueError:以10为基数的int()的文本无效:';0.50';(我无法理解这方面的其他帖子),python,python-3.x,Python,Python 3.x,我无法输入小数,因为它会出现此错误 我试过在不同的地方使用“float”函数 def Change(): Money = int(input("How Much Money Do You Want To Change For Cash? - ")) CoinType = int(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - ")) fl

我无法输入小数,因为它会出现此错误

我试过在不同的地方使用“float”函数

def Change():
  Money = int(input("How Much Money Do You Want To Change For Cash? - "))
  CoinType = int(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))
  float(CoinType)
  if CoinType == 1:
    print("You Will Get", Money / CoinType,"Coins")
  if CoinType == 0.50:
    print("You Will Get", Money / CoinType,"Coins")

它应该出现“你会得到”,货币/硬币类型,“硬币”

你应该使用
浮动

CoinType = float(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))

使用
float
代替
int
。整数(
int
)将不容纳任何十进制

您期望的
int
输入,而您指示用户在以下行中传递一个
浮点
值:

CoinType = int(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))
因此,将其更改为浮动应该可以解决问题:

CoinType = float(input("What Type Of Coin Do You Want To Change Into? (1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01) - "))

尝试用
float
代替
int
sidenote:不要在float中存储货币。使用最小的面额和整数。(因此,100代替1,1代替0.01)。如果真的需要,在最后转换。因为