【发布时间】:2016-01-31 20:01:41
【问题描述】:
我正在再次审查 Python,我来到了这个我再次陷入困境的早期阶段。 我需要:
用 Python 编写一个程序来询问用户的
名称和“重量”以公斤为单位。然后程序将
输出一个句子,以克和磅为单位通知用户他们的体重。
这是我的代码:
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!')
我没有得到正确的输出,而且我得到了 SyntaxErrors。 语法错误在这里:
weightGrams = 'myWeight*1000'
weightPounds = 'myWeight*2.2'
最后:
print(myName+ 'You would weigh', weightGrams, 'in grams and' weightPounds, 'in pounds!')
我该如何解决这些问题?
【问题讨论】:
标签: python input syntax-error user-input