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")
我已经尝试过elif和else,但它在第7行上不起作用。我无法理解它的原因,正如我在youtube上看到的那样,只是使用不同的字符串/输出文本。它在 line7 上对 else 一词表示无效的语法。谁能解释为什么会发生以及如何解决?我在最新的python版本中使用Pycharm
答案 0 :(得分:0)
您可以使用 elif 代替 else ,也可以编写嵌入的if语句(在这方面并不是很重要)。
例如-如果您使用 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))
elif:
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))
else:
if(answer =="convert"):
print ("This function is not available yet")