令牌错误:Python中多行语句中的EOF ......这是什么意思?

lla*_*ara 3 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")
Run Code Online (Sandbox Code Playgroud)

Jon*_*nts 8

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

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')
Run Code Online (Sandbox Code Playgroud)

{name:^20}带有参数name和居中对齐它超过20个字符^20,因此在块内非常适合(计算机监视器?)....

示例输出:

    1111111111111111111111     
    1                    1     
    1                    1     
    1   Hello...         1     
    1       Kevin        1     
    1                    1     
    1                    1     
    1111111111111111111111___  
           11111111          | 
   ------------------------- O 
   .............._... ... 1    
 1...................... 1     
-------------------------  
Run Code Online (Sandbox Code Playgroud)


Mar*_*ers 6

你忘了在两个地方关闭括号:

yORn = int(input("Type 1 to run the program, Type 2 to Exit:  ")) # < 2 closing parenthesis here
Run Code Online (Sandbox Code Playgroud)

再次在代码的最后.

请注意,您的while陈述也有错误; =是作业,你的意思是==:

while yORn == 1:
Run Code Online (Sandbox Code Playgroud)