我在第4行的TypeError
上得到这个。我试过f-strings,甚至str(ageStr) / str(age)
——我在第4行仍然遇到同样的错误
ageStr = "24" #I'm 24 years old.
age = int(ageStr)
print("I'm "+ ageStr +"years old.")
three = "3"
answerYears = age + int(three)
print("The total number of years:" + "answerYears")
answerMonths = answerYears*12
print("In 3 years and 6 months, I'll be " + answerMonths + " months old"
这是你的错误的解决方案
第二种解决方案是简单地删除字符串连接
要打印时,需要将int变量显式类型转换为str:
输出:
相关问题 更多 >
编程相关推荐