python - Where am I screwing up with my output formatting? -


this question has answer here:

so got error message when tried run code (continued previous question) , can't figure out problem is. says it's valueerror can't figure out 1 exactly. maybe it's late, @ loss.

here's 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}{1:27}{2:39}{3:51}\n{4}".format("word", "occurence", "avg. score", "std. dev.", "="*51))      if menu == 1:                dic = ordereddict(sorted(word_avg_dict.items(), key=lambda x:x[1], reverse=false))         key in dic:             print ("{0}{1:27}{2:39:.4f}{3:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key]))     elif menu == 2:         dic = ordereddict(sorted(word_avg_dict.items(), key=lambda x:x[1], reverse=true))         key in dic:             print ("{0}{1:27}{2:39:.4f}{3: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}{1:27}{2:39:.4f}{3: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}{1:27}{2:39:.4f}{3:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key]))      return none 

here's output , error when run it:

you must choose 1 of valid choices of 1, 2, 3, 4          sort options     1. sort avg ascending     2. sort avg descending     3. sort std deviation ascending     4. sort std deviation descending1 wordoccurence                  avg. score                             std. dev.                                           =================================================== traceback (most recent call last):   file "c:\users\ryan\documents\program 7\program 7.py", line 161, in <module>     output = sort(cnt_dict, word_avg_dict, std_dev_dict)   file "c:\users\ryan\documents\program 7\program 7.py", line 104, in sort     print ("{0}{1:27}{2:39:.4f}{3:51:.4f}".format(key, count_dict[key], avg_scores_dict[key], std_dev_dict[key])) valueerror: invalid format specifier 

what messing up? , appreciated!

you shouldn't have multiple colons in single specification field, {3:51:.4f}. remove second one:

>>> print("{0}{1:27}{2:39.4f}{3:51.4f}".format('a', 'b', 1.234567, 9.876543)) ab                                                           1.2346                                             9.8765 

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 -