使用python格式化

时间:2018-07-29 15:40:04

标签: python python-3.x

我目前正在使用一本名为《 学习Python 3的艰难方法》 的书自学Python。我已经完成了练习14(提示和传递),并且我有一些代码需要在PowerShell中显示,但此处无法正常工作。我将按照说明发布以下代码。

from sys import argv

script, user_name = argv
prompt = '>'

print (f"Hi {user_name}, I'm the {script} script.")
print ("I'd like to ask you a few questions.")
print (f"Do you like me {user_name}?")
likes = input(prompt)

print (f"Where do you like {user_name}?")
lives = input(prompt)

print(f"What kind of computers do you have?")
computer = input(prompt)

print(f"""
Alright, so you said {likes} about liking me.
You live in {lives}. Not sure where that is.
And you have a {computer} computer. Nice.
""")

因此,PowerShell不会打印任何内容,因为我收到以下错误:

File "14.py", line 6
    print (f"Hi {user_name}, I'm the {script} script.")
                                                 ^
SyntaxError: invalid syntax

我找不到解决方案。我知道这是因为字符串格式化不起作用,并且我之前还进行了另一次字符串格式化练习,但是我设法解决了该错误并打印了我想要的内容。但是,这很烦人,我正在寻找答案。 有人可以给我一个提示吗?

0 个答案:

没有答案