我正在尝试比较在我的第一个函数中检索到的两个字符串值,但它不起作用。它一直告诉我“语法无效”并将光标移动到elif行。
这是我的计划......
def find_number_of_service():
with open('TheData.txt', 'r') as data_file:
data = data_file.read()
countS = data.count('S')
countW = data.count('W')
print ("There are " + str(countS) + " S's")
print ("There are " + str(countW) + " W's")
return
def find_popular_service():
if (countS) > (countW):
print ("The most used service to buy tickets was the school.")
elif print ("The most used service to buy tickets was the website.")
return
#Main program
find_number_of_service()
find_popular_service()
提前谢谢。
答案 0 :(得分:0)
您没有给elif
条件。 elif
表示otherwise if...
。也许你的意思是else
。
elif
应与if
print ...
应该换行。
答案 1 :(得分:0)
您未正确定义的第二个函数elif
中的问题应该是elif <condition>:
这里是工作函数
def find_popular_service():
if (countS) > (countW):
print ("The most used service to buy tickets was the school.")
else:
print ("The most used service to buy tickets was the website.")
return