python - 尝试打印 int 但结果是 : TypeError must be str, 而不是 float

标签 python python-3.x

我试图让我的程序打印一个字符串后面的 int 。我不确定这是否会影响它或什么,但每当尝试打印时它都会出现错误。

我尝试使用“,”代替,但我不想这样做,因为它输出 The Price Is £ 7.0但它看起来不如£7.0那么好

price = 10
age = int(input("How Old Are You? - "))
if age > 12 and age < 14:
  price = price * 0.7

print("The Price Is £"+price)

最佳答案

发生这种情况是因为你必须连接 int :

print("The Price Is £"+str(price))

关于python - 尝试打印 int 但结果是 : TypeError must be str, 而不是 float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56037087/

相关文章:

python-3.x - KivyMD DatePicker 不随屏幕尺寸调整大小

python-3.x - 在 Ordinal Encoder 中指定编码顺序

python - numpy数组任意列之间的(内存)高效操作

python - 使用 $elemMatch 进行 MongoDB 查询

python - 卡在 python 代码中进行加密。错误是类型 'x' 的对象的未知格式代码 'str'

python - 我如何知道我是否正在调用 numpy.array() 还是使用内置数组函数?

python - 如何将 Pandas 数据框中的列拆分为字母值和数值?

python - 如何将表情符号替换为文本中的单词?

python - 我怎样才能在 python 中解码这个字符串?

python - 将类似文件的对象传递给 ctypes 回调