Align iterable : error “string cannot switch from manual field specification to automatic field...












-1
















This question already has an answer here:




  • ValueError: cannot switch from manual field specification to automatic field numbering

    1 answer




So here is my code :



def f(n):


if n == 0:
return 1
else:
result = 1
for i in range(1,n+1):
result = result * i
return result





def a(n):
sum = 0
z = 0
for i in range(n+1):
sum += f(i)
print('{0:<4}! = {1:<4} no.multi. ={} sum of {}! = {} no.multi. = {}'.format(i,f(i),i,i,sum,z))
z = z + (i+1)


a(19)


I need to get this output: here



But instead i get a sort of pyramid like this



I tried to format inside the brackets but i always get the error : "cannot switch from manual field specification to automatic field numbering"
Thank you in advance










share|improve this question













marked as duplicate by Jean-François Fabre python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 12:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    -1
















    This question already has an answer here:




    • ValueError: cannot switch from manual field specification to automatic field numbering

      1 answer




    So here is my code :



    def f(n):


    if n == 0:
    return 1
    else:
    result = 1
    for i in range(1,n+1):
    result = result * i
    return result





    def a(n):
    sum = 0
    z = 0
    for i in range(n+1):
    sum += f(i)
    print('{0:<4}! = {1:<4} no.multi. ={} sum of {}! = {} no.multi. = {}'.format(i,f(i),i,i,sum,z))
    z = z + (i+1)


    a(19)


    I need to get this output: here



    But instead i get a sort of pyramid like this



    I tried to format inside the brackets but i always get the error : "cannot switch from manual field specification to automatic field numbering"
    Thank you in advance










    share|improve this question













    marked as duplicate by Jean-François Fabre python
    Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 21 '18 at 12:41


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      -1












      -1








      -1









      This question already has an answer here:




      • ValueError: cannot switch from manual field specification to automatic field numbering

        1 answer




      So here is my code :



      def f(n):


      if n == 0:
      return 1
      else:
      result = 1
      for i in range(1,n+1):
      result = result * i
      return result





      def a(n):
      sum = 0
      z = 0
      for i in range(n+1):
      sum += f(i)
      print('{0:<4}! = {1:<4} no.multi. ={} sum of {}! = {} no.multi. = {}'.format(i,f(i),i,i,sum,z))
      z = z + (i+1)


      a(19)


      I need to get this output: here



      But instead i get a sort of pyramid like this



      I tried to format inside the brackets but i always get the error : "cannot switch from manual field specification to automatic field numbering"
      Thank you in advance










      share|improve this question















      This question already has an answer here:




      • ValueError: cannot switch from manual field specification to automatic field numbering

        1 answer




      So here is my code :



      def f(n):


      if n == 0:
      return 1
      else:
      result = 1
      for i in range(1,n+1):
      result = result * i
      return result





      def a(n):
      sum = 0
      z = 0
      for i in range(n+1):
      sum += f(i)
      print('{0:<4}! = {1:<4} no.multi. ={} sum of {}! = {} no.multi. = {}'.format(i,f(i),i,i,sum,z))
      z = z + (i+1)


      a(19)


      I need to get this output: here



      But instead i get a sort of pyramid like this



      I tried to format inside the brackets but i always get the error : "cannot switch from manual field specification to automatic field numbering"
      Thank you in advance





      This question already has an answer here:




      • ValueError: cannot switch from manual field specification to automatic field numbering

        1 answer








      python string format order string-formatting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 12:37









      SamiSami

      104




      104




      marked as duplicate by Jean-François Fabre python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 12:41


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Jean-François Fabre python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 12:41


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          I declared variable strong_i which is string of i with !, to take into account ! when choosing amount of spaces when printing i with !.



          def f(n):
          if n == 0:
          return 1
          else:
          result = 1
          for i in range(1,n+1):
          result = result * i
          return result

          def a(n):
          sum = 0
          z = 0
          for i in range(n+1):
          sum += f(i)
          strong_i = str(i) + '!'
          print('{0:<4}= {1:<20} no.multi. = {2:<2} sum of {3:<3} = {4:<20} no.multi. = {5}'.format(strong_i,f(i),i,strong_i,sum,z))
          z = z + (i+1)

          a(19)


          Output:



          0!  = 1                     no.multi. = 0  sum of 0!   = 1                      no.multi. = 0
          1! = 1 no.multi. = 1 sum of 1! = 2 no.multi. = 1
          2! = 2 no.multi. = 2 sum of 2! = 4 no.multi. = 3
          3! = 6 no.multi. = 3 sum of 3! = 10 no.multi. = 6
          4! = 24 no.multi. = 4 sum of 4! = 34 no.multi. = 10
          5! = 120 no.multi. = 5 sum of 5! = 154 no.multi. = 15
          6! = 720 no.multi. = 6 sum of 6! = 874 no.multi. = 21
          7! = 5040 no.multi. = 7 sum of 7! = 5914 no.multi. = 28
          8! = 40320 no.multi. = 8 sum of 8! = 46234 no.multi. = 36
          9! = 362880 no.multi. = 9 sum of 9! = 409114 no.multi. = 45
          10! = 3628800 no.multi. = 10 sum of 10! = 4037914 no.multi. = 55
          11! = 39916800 no.multi. = 11 sum of 11! = 43954714 no.multi. = 66
          12! = 479001600 no.multi. = 12 sum of 12! = 522956314 no.multi. = 78
          13! = 6227020800 no.multi. = 13 sum of 13! = 6749977114 no.multi. = 91
          14! = 87178291200 no.multi. = 14 sum of 14! = 93928268314 no.multi. = 105
          15! = 1307674368000 no.multi. = 15 sum of 15! = 1401602636314 no.multi. = 120
          16! = 20922789888000 no.multi. = 16 sum of 16! = 22324392524314 no.multi. = 136
          17! = 355687428096000 no.multi. = 17 sum of 17! = 378011820620314 no.multi. = 153
          18! = 6402373705728000 no.multi. = 18 sum of 18! = 6780385526348314 no.multi. = 171
          19! = 121645100408832000 no.multi. = 19 sum of 19! = 128425485935180314 no.multi. = 190





          share|improve this answer
























          • Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

            – Sami
            Nov 21 '18 at 13:04













          • Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

            – Filip Młynarski
            Nov 21 '18 at 13:07


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I declared variable strong_i which is string of i with !, to take into account ! when choosing amount of spaces when printing i with !.



          def f(n):
          if n == 0:
          return 1
          else:
          result = 1
          for i in range(1,n+1):
          result = result * i
          return result

          def a(n):
          sum = 0
          z = 0
          for i in range(n+1):
          sum += f(i)
          strong_i = str(i) + '!'
          print('{0:<4}= {1:<20} no.multi. = {2:<2} sum of {3:<3} = {4:<20} no.multi. = {5}'.format(strong_i,f(i),i,strong_i,sum,z))
          z = z + (i+1)

          a(19)


          Output:



          0!  = 1                     no.multi. = 0  sum of 0!   = 1                      no.multi. = 0
          1! = 1 no.multi. = 1 sum of 1! = 2 no.multi. = 1
          2! = 2 no.multi. = 2 sum of 2! = 4 no.multi. = 3
          3! = 6 no.multi. = 3 sum of 3! = 10 no.multi. = 6
          4! = 24 no.multi. = 4 sum of 4! = 34 no.multi. = 10
          5! = 120 no.multi. = 5 sum of 5! = 154 no.multi. = 15
          6! = 720 no.multi. = 6 sum of 6! = 874 no.multi. = 21
          7! = 5040 no.multi. = 7 sum of 7! = 5914 no.multi. = 28
          8! = 40320 no.multi. = 8 sum of 8! = 46234 no.multi. = 36
          9! = 362880 no.multi. = 9 sum of 9! = 409114 no.multi. = 45
          10! = 3628800 no.multi. = 10 sum of 10! = 4037914 no.multi. = 55
          11! = 39916800 no.multi. = 11 sum of 11! = 43954714 no.multi. = 66
          12! = 479001600 no.multi. = 12 sum of 12! = 522956314 no.multi. = 78
          13! = 6227020800 no.multi. = 13 sum of 13! = 6749977114 no.multi. = 91
          14! = 87178291200 no.multi. = 14 sum of 14! = 93928268314 no.multi. = 105
          15! = 1307674368000 no.multi. = 15 sum of 15! = 1401602636314 no.multi. = 120
          16! = 20922789888000 no.multi. = 16 sum of 16! = 22324392524314 no.multi. = 136
          17! = 355687428096000 no.multi. = 17 sum of 17! = 378011820620314 no.multi. = 153
          18! = 6402373705728000 no.multi. = 18 sum of 18! = 6780385526348314 no.multi. = 171
          19! = 121645100408832000 no.multi. = 19 sum of 19! = 128425485935180314 no.multi. = 190





          share|improve this answer
























          • Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

            – Sami
            Nov 21 '18 at 13:04













          • Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

            – Filip Młynarski
            Nov 21 '18 at 13:07
















          0














          I declared variable strong_i which is string of i with !, to take into account ! when choosing amount of spaces when printing i with !.



          def f(n):
          if n == 0:
          return 1
          else:
          result = 1
          for i in range(1,n+1):
          result = result * i
          return result

          def a(n):
          sum = 0
          z = 0
          for i in range(n+1):
          sum += f(i)
          strong_i = str(i) + '!'
          print('{0:<4}= {1:<20} no.multi. = {2:<2} sum of {3:<3} = {4:<20} no.multi. = {5}'.format(strong_i,f(i),i,strong_i,sum,z))
          z = z + (i+1)

          a(19)


          Output:



          0!  = 1                     no.multi. = 0  sum of 0!   = 1                      no.multi. = 0
          1! = 1 no.multi. = 1 sum of 1! = 2 no.multi. = 1
          2! = 2 no.multi. = 2 sum of 2! = 4 no.multi. = 3
          3! = 6 no.multi. = 3 sum of 3! = 10 no.multi. = 6
          4! = 24 no.multi. = 4 sum of 4! = 34 no.multi. = 10
          5! = 120 no.multi. = 5 sum of 5! = 154 no.multi. = 15
          6! = 720 no.multi. = 6 sum of 6! = 874 no.multi. = 21
          7! = 5040 no.multi. = 7 sum of 7! = 5914 no.multi. = 28
          8! = 40320 no.multi. = 8 sum of 8! = 46234 no.multi. = 36
          9! = 362880 no.multi. = 9 sum of 9! = 409114 no.multi. = 45
          10! = 3628800 no.multi. = 10 sum of 10! = 4037914 no.multi. = 55
          11! = 39916800 no.multi. = 11 sum of 11! = 43954714 no.multi. = 66
          12! = 479001600 no.multi. = 12 sum of 12! = 522956314 no.multi. = 78
          13! = 6227020800 no.multi. = 13 sum of 13! = 6749977114 no.multi. = 91
          14! = 87178291200 no.multi. = 14 sum of 14! = 93928268314 no.multi. = 105
          15! = 1307674368000 no.multi. = 15 sum of 15! = 1401602636314 no.multi. = 120
          16! = 20922789888000 no.multi. = 16 sum of 16! = 22324392524314 no.multi. = 136
          17! = 355687428096000 no.multi. = 17 sum of 17! = 378011820620314 no.multi. = 153
          18! = 6402373705728000 no.multi. = 18 sum of 18! = 6780385526348314 no.multi. = 171
          19! = 121645100408832000 no.multi. = 19 sum of 19! = 128425485935180314 no.multi. = 190





          share|improve this answer
























          • Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

            – Sami
            Nov 21 '18 at 13:04













          • Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

            – Filip Młynarski
            Nov 21 '18 at 13:07














          0












          0








          0







          I declared variable strong_i which is string of i with !, to take into account ! when choosing amount of spaces when printing i with !.



          def f(n):
          if n == 0:
          return 1
          else:
          result = 1
          for i in range(1,n+1):
          result = result * i
          return result

          def a(n):
          sum = 0
          z = 0
          for i in range(n+1):
          sum += f(i)
          strong_i = str(i) + '!'
          print('{0:<4}= {1:<20} no.multi. = {2:<2} sum of {3:<3} = {4:<20} no.multi. = {5}'.format(strong_i,f(i),i,strong_i,sum,z))
          z = z + (i+1)

          a(19)


          Output:



          0!  = 1                     no.multi. = 0  sum of 0!   = 1                      no.multi. = 0
          1! = 1 no.multi. = 1 sum of 1! = 2 no.multi. = 1
          2! = 2 no.multi. = 2 sum of 2! = 4 no.multi. = 3
          3! = 6 no.multi. = 3 sum of 3! = 10 no.multi. = 6
          4! = 24 no.multi. = 4 sum of 4! = 34 no.multi. = 10
          5! = 120 no.multi. = 5 sum of 5! = 154 no.multi. = 15
          6! = 720 no.multi. = 6 sum of 6! = 874 no.multi. = 21
          7! = 5040 no.multi. = 7 sum of 7! = 5914 no.multi. = 28
          8! = 40320 no.multi. = 8 sum of 8! = 46234 no.multi. = 36
          9! = 362880 no.multi. = 9 sum of 9! = 409114 no.multi. = 45
          10! = 3628800 no.multi. = 10 sum of 10! = 4037914 no.multi. = 55
          11! = 39916800 no.multi. = 11 sum of 11! = 43954714 no.multi. = 66
          12! = 479001600 no.multi. = 12 sum of 12! = 522956314 no.multi. = 78
          13! = 6227020800 no.multi. = 13 sum of 13! = 6749977114 no.multi. = 91
          14! = 87178291200 no.multi. = 14 sum of 14! = 93928268314 no.multi. = 105
          15! = 1307674368000 no.multi. = 15 sum of 15! = 1401602636314 no.multi. = 120
          16! = 20922789888000 no.multi. = 16 sum of 16! = 22324392524314 no.multi. = 136
          17! = 355687428096000 no.multi. = 17 sum of 17! = 378011820620314 no.multi. = 153
          18! = 6402373705728000 no.multi. = 18 sum of 18! = 6780385526348314 no.multi. = 171
          19! = 121645100408832000 no.multi. = 19 sum of 19! = 128425485935180314 no.multi. = 190





          share|improve this answer













          I declared variable strong_i which is string of i with !, to take into account ! when choosing amount of spaces when printing i with !.



          def f(n):
          if n == 0:
          return 1
          else:
          result = 1
          for i in range(1,n+1):
          result = result * i
          return result

          def a(n):
          sum = 0
          z = 0
          for i in range(n+1):
          sum += f(i)
          strong_i = str(i) + '!'
          print('{0:<4}= {1:<20} no.multi. = {2:<2} sum of {3:<3} = {4:<20} no.multi. = {5}'.format(strong_i,f(i),i,strong_i,sum,z))
          z = z + (i+1)

          a(19)


          Output:



          0!  = 1                     no.multi. = 0  sum of 0!   = 1                      no.multi. = 0
          1! = 1 no.multi. = 1 sum of 1! = 2 no.multi. = 1
          2! = 2 no.multi. = 2 sum of 2! = 4 no.multi. = 3
          3! = 6 no.multi. = 3 sum of 3! = 10 no.multi. = 6
          4! = 24 no.multi. = 4 sum of 4! = 34 no.multi. = 10
          5! = 120 no.multi. = 5 sum of 5! = 154 no.multi. = 15
          6! = 720 no.multi. = 6 sum of 6! = 874 no.multi. = 21
          7! = 5040 no.multi. = 7 sum of 7! = 5914 no.multi. = 28
          8! = 40320 no.multi. = 8 sum of 8! = 46234 no.multi. = 36
          9! = 362880 no.multi. = 9 sum of 9! = 409114 no.multi. = 45
          10! = 3628800 no.multi. = 10 sum of 10! = 4037914 no.multi. = 55
          11! = 39916800 no.multi. = 11 sum of 11! = 43954714 no.multi. = 66
          12! = 479001600 no.multi. = 12 sum of 12! = 522956314 no.multi. = 78
          13! = 6227020800 no.multi. = 13 sum of 13! = 6749977114 no.multi. = 91
          14! = 87178291200 no.multi. = 14 sum of 14! = 93928268314 no.multi. = 105
          15! = 1307674368000 no.multi. = 15 sum of 15! = 1401602636314 no.multi. = 120
          16! = 20922789888000 no.multi. = 16 sum of 16! = 22324392524314 no.multi. = 136
          17! = 355687428096000 no.multi. = 17 sum of 17! = 378011820620314 no.multi. = 153
          18! = 6402373705728000 no.multi. = 18 sum of 18! = 6780385526348314 no.multi. = 171
          19! = 121645100408832000 no.multi. = 19 sum of 19! = 128425485935180314 no.multi. = 190






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 12:45









          Filip MłynarskiFilip Młynarski

          1,7711413




          1,7711413













          • Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

            – Sami
            Nov 21 '18 at 13:04













          • Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

            – Filip Młynarski
            Nov 21 '18 at 13:07



















          • Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

            – Sami
            Nov 21 '18 at 13:04













          • Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

            – Filip Młynarski
            Nov 21 '18 at 13:07

















          Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

          – Sami
          Nov 21 '18 at 13:04







          Thank you very much, but i still don't understand how the ' ! ' affects the output, in such a way that it needs to be isolated

          – Sami
          Nov 21 '18 at 13:04















          Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

          – Filip Młynarski
          Nov 21 '18 at 13:07





          Here's simple example print('{0:<5}!.'.format(10)) that gives us 10 !. because spaces are placed between our number and '!', but if we would do it this way print('{0:<5}.'.format('10!')) we'll get 10! .

          – Filip Młynarski
          Nov 21 '18 at 13:07





          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]