权重 python 错误 SyntaxError

Weight python mistake SyntaxError

我又在复习了Python,又到了这个早期阶段,又卡住了。 我需要:

Write a program in Python that will ask for the user's
Name and 'weight' in kilograms. The program will then
Output a sentence informing the user of their weight in grams and in pounds.

这是我的代码:

myName = str(input('What is your name?:'))

myWeight = int(input( myName+ 'What is your weight in kilograms?:')

weightGrams = 'myWeight*1000'
weightPounds = 'myWeight*2.2'



print(myName+ 'You would weigh', weightGrams, 'in grams and' weightPounds, 'in pounds!')

我没有得到正确的输出,而且我得到了语法错误。 语法错误在这里:

weightGrams = 'myWeight*1000'
weightPounds = 'myWeight*2.2'

最后:

print(myName+ 'You would weigh', weightGrams, 'in grams and' weightPounds, 'in pounds!')

我该如何解决这些问题?

不要将 int 视为 string:

weightGrams = myWeight*1000
weightPounds = myWeight*2.2

你的 print:

中也有语法错误
print(myName+ ' You would weigh', weightGrams, 'in grams and', weightPounds, 'in pounds!')

此外,您不需要在此处强制转换为 str,因为 input 已经给出 string:

myName = input('What is your name?:')

最终编辑:您在此处缺少右括号 )

myWeight = int(input( myName+ 'What is your weight in kilograms?:'))