python - token 错误 : EOF in multiline statement in Python. .. 这是什么意思?

标签 python token eof

我刚开始学习如何编码,我正在学习 Python。我正在尝试编写一个程序,每次用户键入 1 时都会打印 ASCII 艺术,但是当我尝试运行该模块时,它会在标题中显示错误。

这是我的代码: 我哪里出错了?

yORn = int(input("Type 1 to run the program, Type 2 to Exit:  ")
while yORn = 1:
   Name = str(input("What is your name?"))
   print("      1111111111111111111111     ")
   print("      1                    1     ")
   print("      1                    1     ")
   print("      1   Hello...         1     ")
   print("      1        ", Name,"   1     ")
   print("      1                    1     ")
   print("      1                    1     ")
   print("      1111111111111111111111___  ")
   print("             11111111          | ")
   print("     ------------------------- O ")
   print("    1.............._... ... 1    ")
   print("   1...................... 1     ")
   print("  -------------------------      ")
   yORn = int(input("Type 1 to run the program, Type 2 to Exit:  ")
print ("GoodBye")

最佳答案

你已经得到了直接的答案(缺少括号),但如果你正在做这样的事情,我会建议另一种方法,并使用多行字符串(使用三重引号字符串)和字符串格式:

ascii_art = """
    1111111111111111111111     
    1                    1     
    1                    1     
    1   Hello...         1     
    1{name:^20}1     
    1                    1     
    1                    1     
    1111111111111111111111___  
           11111111          | 
   ------------------------- O 
   .............._... ... 1    
 1...................... 1     
-------------------------          
"""

print ascii_art.format(name='Kevin')

{name:^20} 采用参数 name 并将其居中对齐在 20 个字符 ^20 内,因此它非常适合 block (电脑显示器?)......

示例输出:

    1111111111111111111111     
    1                    1     
    1                    1     
    1   Hello...         1     
    1       Kevin        1     
    1                    1     
    1                    1     
    1111111111111111111111___  
           11111111          | 
   ------------------------- O 
   .............._... ... 1    
 1...................... 1     
-------------------------  

关于python - token 错误 : EOF in multiline statement in Python. .. 这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14526768/

相关文章:

python - pip 安装被杀死

python - 用于 Android 和 utf-16-be 编码的 Pygame 子集

python - 如何查找对特定数据有效的所有 HTML 标签的列表

oauth - 为什么我们必须在 OAuth 中使用 "change temporary credentials for token credentials"?

c - strtok 内部的 strtok 无法使用原始 token 的副本 - C

c - 如何在 C 中接受一定数量的输入

php - 当optimized_write设置为True时,是否可以使用Openpyxl并行创建多个Excel文件?

android - 清除应用程序数据不清除 GCM token 或 GCM 订阅主题

c - 标准输入中的文件结尾

qt - 如何正确确定 QTCPSocket 中已到达输入结束?