If statement 我在陈述方面有困难
我试过使用elif和else,但它在第7行不起作用。我不能理解,因为这和我在youtube上看到的完全一样,只是用不同的字符串/输出文本学习。它表示第7行上的单词else的语法无效。有人能解释为什么会发生这种情况,以及如何解决它吗?我将Pycharm与最新的python版本一起使用您可以使用elif而不是else,或者您可以编写一个嵌入的if语句(这并不是很重要) 例如-如果您使用了elif:If statement 我在陈述方面有困难,if-statement,choice,multiple-choice,If Statement,Choice,Multiple Choice,我试过使用elif和else,但它在第7行不起作用。我不能理解,因为这和我在youtube上看到的完全一样,只是用不同的字符串/输出文本学习。它表示第7行上的单词else的语法无效。有人能解释为什么会发生这种情况,以及如何解决它吗?我将Pycharm与最新的python版本一起使用您可以使用elif而不是else,或者您可以编写一个嵌入的if语句(这并不是很重要) 例如-如果您使用了elif: answer = input ("Type count for counting and conver
answer = input ("Type count for counting and convert for converting ")
if (answer == "count"):
text = input("Paste your text to count it: ")
print(len(text))
else(answer =="convert"):
print ("This function is not available yet")
^^这与写作基本相同:
answer = input ("Type count for counting and convert for converting ")
if (answer == "count"):
text = input("Paste your text to count it: ")
print(len(text))
elif:
print ("This function is not available yet")
else
没有条件。使用elif
。此外,这里似乎缺少一个右括号:print(len(text))我用elif试过了,但没有任何区别
answer = input ("Type count for counting and convert for converting ")
if (answer == "count"):
text = input("Paste your text to count it: ")
print(len(text))
else:
if(answer =="convert"):
print ("This function is not available yet")