“ TypeError:只能将元组(不是“ str”)连接到元组”错误

时间:2019-12-19 09:55:50

标签: python python-3.x

我是python的新手,我正在尝试学习我编写了这小段代码

weight = input('How much do you weigh in pounds? ')
weight_kg = int(weight)* 0,453592
print (weight_kg + 'is your weight is kilogrammes')

但是当我运行它时,出现此错误

Traceback (most recent call last):
  File "C:/Users/hh/Desktop/PYTHON-LEARNING!/app.py", line 3, in <module>
    print (weight_kg + 'hi')
TypeError: can only concatenate tuple (not "str") to tuple

1 个答案:

答案 0 :(得分:1)

这里有两个问题,一个是您将浮点数乘以逗号作为小数点分隔符,第二个问题是您无法在print语句中连接浮点数和字符串。下面是固定的代码-我使用f字符串打印最终输出,这需要Python 3.6。

weight = input('How much do you weigh in pounds? ')
weight_kg = int(weight)* 0.453592
print (f"{weight_kg} is your weight is kilogrammes")