<small id='8GM8L'></small><noframes id='8GM8L'>

    • <bdo id='8GM8L'></bdo><ul id='8GM8L'></ul>

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

      1. TypeError:在字符串格式化python期间并非所有参数都转换了

        时间:2024-04-21
        <legend id='F3OHF'><style id='F3OHF'><dir id='F3OHF'><q id='F3OHF'></q></dir></style></legend>
      2. <tfoot id='F3OHF'></tfoot>

      3. <small id='F3OHF'></small><noframes id='F3OHF'>

              <bdo id='F3OHF'></bdo><ul id='F3OHF'></ul>

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

                  <tbody id='F3OHF'></tbody>
                1. 本文介绍了TypeError:在字符串格式化python期间并非所有参数都转换了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  The program is supposed to take in two names, and if they are the same length it should check if they are the same word. If it's the same word it will print "The names are the same". If they are the same length but with different letters it will print "The names are different but the same length". The part I'm having a problem with is in the bottom 4 lines.

                  #!/usr/bin/env python
                  # Enter your code for "What's In (The Length Of) A Name?" here.
                  name1 = input("Enter name 1: ")
                  name2 = input("Enter name 2: ")
                  len(name1)
                  len(name2)
                  if len(name1) == len(name2):
                      if name1 == name2:
                          print ("The names are the same")
                      else:
                          print ("The names are different, but are the same length")
                      if len(name1) > len(name2):
                          print ("'{0}' is longer than '{1}'"% name1, name2)
                      elif len(name1) < len(name2):
                          print ("'{0}'is longer than '{1}'"% name2, name1)
                  

                  When I run this code it displays:

                  Traceback (most recent call last):
                    File "program.py", line 13, in <module>
                      print ("'{0}' is longer than '{1}'"% name1, name2)
                  TypeError: not all arguments converted during string formatting
                  

                  Any suggestions are highly appreciated.

                  解决方案

                  You're mixing different format functions.

                  The old-style % formatting uses % codes for formatting:

                  'It will cost $%d dollars.' % 95
                  

                  The new-style {} formatting uses {} codes and the .format method

                  'It will cost ${0} dollars.'.format(95)
                  

                  Note that with old-style formatting, you have to specify multiple arguments using a tuple:

                  '%d days and %d nights' % (40, 40)
                  


                  In your case, since you're using {} format specifiers, use .format:

                  "'{0}' is longer than '{1}'".format(name1, name2)
                  

                  这篇关于TypeError:在字符串格式化python期间并非所有参数都转换了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:TypeError:需要一个类似字节的对象,而不是“str" 下一篇:PermissionError:Python 中的 [Errno 13]

                  相关文章

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

                  • <bdo id='jP2Wx'></bdo><ul id='jP2Wx'></ul>
                  <tfoot id='jP2Wx'></tfoot>

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