ValueError:基为10的int()的文本无效:“0.50”(我无法理解有关此的其他帖子)

2024-04-19 10:05:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我不能输入小数点,因为它出现了这个错误

我试过把“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")

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


Tags: toyouinputgetiffloatchangedo
3条回答

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

您需要int输入,而您指示用户在以下行中传递float值:

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 = 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

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) - "))

相关问题 更多 >