当我尝试运行我的代码时,它说我的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")
答案 0 :(得分:3)
在python中缩进很重要,请确保else
与if
位于同一缩进列。如前所述,您需要在:
的末尾加上else
。即else:
答案 1 :(得分:0)
尝试“其他:”
我相信它缺少冒号。
答案 2 :(得分:0)
缩进else
在else
说明:
else
,if
,elif
,with
等是在语句后需要冒号的语句答案 3 :(得分:0)
在其他字符后加冒号,而其他字符的缩进是错误的
class PageThreeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_page_three)
val btnListen = findViewById<Button>(R.id.btnListen)
btnListen.setOnClickListener() {
Toast.makeText(this@PageThreeActivity, "This is a Toast Message", Toast.LENGTH_SHORT).show()
}
}// end onCreate
fun onLISTEN(view: View) {
val intent = Intent(this@PageThreeActivity, MainActivity::class.java)
startActivity(intent)
}