python - python3中else语句的语法无效
问题描述
当我尝试运行我的代码时,它说我的 else 语句的语法无效,但我不知道出了什么问题。
import random
import time
username = input("Hello. Please enter your name, then press 'enter'.
After you type something, you will need to /n"
"click the 'enter' key to send it")
print ("Hello " + username)
time.sleep(3)
game_tutorial_input = input("Do you wish to see the tutorial? (y/n)")
if game_tutorial_input == "y":
print ("Great! Press enter after each instruction to move /n"
"onto the next one.")
else
print("Are you sure? (y/n")
解决方案
缩进在 python 中很重要,确保else
与 .indent 在同一缩进列上if
。并且如前所述,您需要 a:
在else
.. 的末尾,即else:
推荐阅读
- r - 加速极慢的 for 循环
- c - 如何从表单文件中打印有序的登录数据:C 中的用户、小时、分钟
- mysql - CakePHP 4:如何将关联结果计数添加到 where 条件
- ios - 我的 react-native 应用程序在调试模式下启动良好,但是在构建发布时,启动时崩溃
- c# - xaml (WPF MVVM) 无法识别模型的属性
- go - Go websocket 测试表现奇怪
- discord.py - 如何将命令名称和前缀后面的所有文本放入异步 def 中的 rest_of_message 之类的变量中?
- odata - Teiid wildlfy - 表列加密/解密
- python - 如何根据列的多个值删除行?
- date - Is the date in the next 14 days or later