我试图让我的程序打印一个字符串后面的 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/