python 3.x - Function if/elif/else syntax error -


i can't figure out why getting syntax error function wrote. occurs @ first elif. when try run it, error in idle says "invalid syntax" highlights 'elif'.

the code:

def sort(count_dict, avg_scores_dict, std_dev_dict):     '''sorts , prints output'''     menu = menu_validate("you must choose 1 of valid choices of 1, 2, 3, 4 \n        sort options\n    1. sort avg ascending\n    2. sort avg descending\n    3. sort std deviation ascending\n    4. sort std deviation descending", 1, 4)     print ("{}{0:27}{0:39}{0:51}\n{}".format("word", "occurence", "avg. score", "std. dev.", "="*51))      if menu == 1:                dic = ordereddict(sorted(word_average_dict.items(), key=lambda x:x[1], reverse=false))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key])      elif menu == 2:         dic = ordereddict(sorted(word_average_dict.items(), key=lambda x:x[1], reverse=true))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key])      elif menu == 3:         dic = ordereddict(sorted(std_dev_dict.items(), key=lambda x:x[1], reverse=false))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key])      elif menu == 4:         dic = ordereddict(sorted(std_dev_dict.items(), key=lambda x:x[1], reverse=true))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key])      return none 

also, print formatting correct? it's supposed justify on right many spaces , last 2 floats 4th decimal place.

any appreciated!

it seems you're entering blank line in between start of every elif.

try this:

def sort(count_dict, avg_scores_dict, std_dev_dict):     '''sorts , prints output'''     menu = menu_validate("you must choose 1 of valid choices of 1, 2, 3, 4 \n        sort options\n    1. sort avg ascending\n    2. sort avg descending\n    3. sort std deviation ascending\n    4. sort std deviation descending", 1, 4)     print ("{}{0:27}{0:39}{0:51}\n{}".format("word", "occurence", "avg. score", "std. dev.", "="*51))      if menu == 1:                dic = ordereddict(sorted(word_average_dict.items(), key=lambda x:x[1], reverse=false))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key]))     elif menu == 2:         dic = ordereddict(sorted(word_average_dict.items(), key=lambda x:x[1], reverse=true))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key]))     elif menu == 3:         dic = ordereddict(sorted(std_dev_dict.items(), key=lambda x:x[1], reverse=false))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key]))     elif menu == 4:         dic = ordereddict(sorted(std_dev_dict.items(), key=lambda x:x[1], reverse=true))         key in dic:             print ("{}{0:27}{0:39:.4f}{0:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key]))     return none 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -