• <i id='C2yZy'><tr id='C2yZy'><dt id='C2yZy'><q id='C2yZy'><span id='C2yZy'><b id='C2yZy'><form id='C2yZy'><ins id='C2yZy'></ins><ul id='C2yZy'></ul><sub id='C2yZy'></sub></form><legend id='C2yZy'></legend><bdo id='C2yZy'><pre id='C2yZy'><center id='C2yZy'></center></pre></bdo></b><th id='C2yZy'></th></span></q></dt></tr></i><div id='C2yZy'><tfoot id='C2yZy'></tfoot><dl id='C2yZy'><fieldset id='C2yZy'></fieldset></dl></div>
      <bdo id='C2yZy'></bdo><ul id='C2yZy'></ul>

        <legend id='C2yZy'><style id='C2yZy'><dir id='C2yZy'><q id='C2yZy'></q></dir></style></legend>
      1. <small id='C2yZy'></small><noframes id='C2yZy'>

        <tfoot id='C2yZy'></tfoot>
      2. 我在哪里弄乱了输出格式?

        时间:2023-10-09

        • <i id='Wd15p'><tr id='Wd15p'><dt id='Wd15p'><q id='Wd15p'><span id='Wd15p'><b id='Wd15p'><form id='Wd15p'><ins id='Wd15p'></ins><ul id='Wd15p'></ul><sub id='Wd15p'></sub></form><legend id='Wd15p'></legend><bdo id='Wd15p'><pre id='Wd15p'><center id='Wd15p'></center></pre></bdo></b><th id='Wd15p'></th></span></q></dt></tr></i><div id='Wd15p'><tfoot id='Wd15p'></tfoot><dl id='Wd15p'><fieldset id='Wd15p'></fieldset></dl></div>

            <legend id='Wd15p'><style id='Wd15p'><dir id='Wd15p'><q id='Wd15p'></q></dir></style></legend>

            <small id='Wd15p'></small><noframes id='Wd15p'>

                <tbody id='Wd15p'></tbody>
                • <bdo id='Wd15p'></bdo><ul id='Wd15p'></ul>

                • <tfoot id='Wd15p'></tfoot>
                • 本文介绍了我在哪里弄乱了输出格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  因此,当我尝试运行我的代码时收到一条错误消息,但我无法弄清楚究竟是什么问题.它说这是一个 ValueError 但我无法确定到底是哪一个.或许只是来晚了,但我不知所措.

                  So I got an error message when I tried to run my code and I can't figure out what exactly the problem is. It says it's a ValueError but I can't figure out which one exactly. Maybe it's just late, but I am at a loss.

                  这是我的代码:

                  def sort(count_dict, avg_scores_dict, std_dev_dict):
                      '''sorts and prints the output'''
                      menu = menu_validate("You must choose one of the valid choices of 1, 2, 3, 4 
                          Sort Options
                      1. Sort by Avg Ascending
                      2. Sort by Avg Descending
                      3. Sort by Std Deviation Ascending
                      4. Sort by Std Deviation Descending", 1, 4)
                      print ("{}{0:27}{0:39}{0:51}
                  {}".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))
                          for 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))
                          for 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))
                          for 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))
                          for 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
                  

                  这是我运行时的输出和错误:

                  Here's my output and error when I run it:

                  You must choose one of the valid choices of 1, 2, 3, 4 
                          Sort Options
                      1. Sort by Avg Ascending
                      2. Sort by Avg Descending
                      3. Sort by Std Deviation Ascending
                      4. Sort by Std Deviation Descending1
                  Traceback (most recent call last):
                    File "C:UsersRyanDocumentsProgram 7Program 7.py", line 161, in <module>
                      output = sort(cnt_dict, word_avg_dict, std_dev_dict)
                    File "C:UsersRyanDocumentsProgram 7Program 7.py", line 99, in sort
                      print ("{}{0:27}{0:39}{0:51}
                  {}".format("Word", "Occurence", "Avg. Score", "Std. Dev.", "="*51))
                  ValueError: cannot switch from automatic field numbering to manual field specification
                  

                  我在搞砸什么?感谢您提供任何和所有帮助!

                  What am I messing up? Any and all help is appreciated!

                  推荐答案

                  您不能在自动字段编号(通过指定简单的 {} 获得的结果)和手动字段之间来回切换规范,例如{0}.如果您希望同一个字段重复多次,如 'Word' 在您的示例中,您还必须指定您希望其他字段是什么.例如,您可能希望从第一个参数 'Word'(即元素 0)和第五个参数 '='*51,作为最后一个,即元素4:

                  You can't switch back and forth between automatic field numbering - what you get by specifying a simple {} - and manual field specification, e.g. {0}. If you want the same field repeated several times, as 'Word' is in your example, you'll have to also specify what you want the other fields to be. For example, you might want to start with the first argument, 'Word', which is element 0, and the fifth argument, '='*51, as the last, which is element 4:

                  >>> print("{0}{0:27}{0:39}{0:51}
                  {4}".format("Word", "Occurence", "Avg. Score", "Std. Dev.", "="*51))
                  WordWord                       Word                                   Word
                  
                  ===================================================
                  

                  您必须自己决定要将哪些参数放在格式字符串中的哪个位置.

                  You'll have to decide for yourself which arguments you want to be placed where in the format string.

                  这篇关于我在哪里弄乱了输出格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:dict 格式的键错误“0" 下一篇:加载 svmlight 格式错误

                  相关文章

                  最新文章

                  <i id='ksNaF'><tr id='ksNaF'><dt id='ksNaF'><q id='ksNaF'><span id='ksNaF'><b id='ksNaF'><form id='ksNaF'><ins id='ksNaF'></ins><ul id='ksNaF'></ul><sub id='ksNaF'></sub></form><legend id='ksNaF'></legend><bdo id='ksNaF'><pre id='ksNaF'><center id='ksNaF'></center></pre></bdo></b><th id='ksNaF'></th></span></q></dt></tr></i><div id='ksNaF'><tfoot id='ksNaF'></tfoot><dl id='ksNaF'><fieldset id='ksNaF'></fieldset></dl></div>
                  <tfoot id='ksNaF'></tfoot>
                  1. <legend id='ksNaF'><style id='ksNaF'><dir id='ksNaF'><q id='ksNaF'></q></dir></style></legend>

                      <bdo id='ksNaF'></bdo><ul id='ksNaF'></ul>
                  2. <small id='ksNaF'></small><noframes id='ksNaF'>