Can't loop a while loop











up vote
1
down vote

favorite












So I want to do a while loop just to calculate the integral of some random functions. The thing is that when I pass opción = 1 it does the first if (good) but when I pass other number it breaks. Obviously, because True = 1 and False = 0. So how can I do it to do the while loop until (1,2,3) until I press 4... Thanks you so much in advance



while opcion == True:
if opcion == 1:
print('Vamos a calcular la siguiente integral:')
f = a*x + b
integral = sp.Integral(f, x)
sp.pprint(integral)
print()
print('Que tiene como resultado:')
sp.pprint(sp.integrate(f,x))
print()
print('Introducimos los límites y valores de las'
' constantes para caluclarla')
lim_inf = int(input('Límite inferior = '))
lim_sup = int(input('Límite superior = '))
while (lim_inf == lim_sup):
print('Los límites no pueden ser iguales !! '
'Vuelve a introducir valores diferentes')
lim_inf = int(input('Límite inferior = '))
lim_sup = int(input('Límite superior = '))
a = int(input('valor a = '))
b = int(input('valor de b = '))
res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
print()
print('Valor de la integral',res[0])

elif opcion == 2:
print('Vamos a calcular la siguiente integral:')
f = a*x**2 + b*x + c
integral = sp.Integral(f, x)
sp.pprint(integral)
print()
print('Que tiene como resultado:')
sp.pprint(sp.integrate(f,x))
print()
print('Introducimos los límites y valores de las'
' constantes para caluclarla')
lim_inf = int(input('Límite inferior = '))
lim_sup = int(input('Límite superior = '))
while (lim_inf == lim_sup):
print('Los límites no pueden ser iguales !! '
'Vuelve a introducir valores diferentes')
lim_inf = int(input('Límite inferior = '))
lim_sup = int(input('Límite superior = '))
a = int(input('valor a = '))
b = int(input('valor de b = '))
res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
print()
print('Valor de la integral',res[0])

elif opcion == 3:
print('Vamos a calcular la siguiente integral:')
f = a*x**3 + b*x**2 + c*x**2 + d
integral = sp.Integral(f, x)
sp.pprint(integral)
print()
print('Que tiene como resultado:')
sp.pprint(sp.integrate(f,x))
print()
print('Introducimos los límites y valores de las'
' constantes para caluclarla')
lim_inf = int(input('Límite inferior = '))
lim_sup = int(input('Límite superior = '))
while (lim_inf == lim_sup):
print('Los límites no pueden ser iguales !! '
'Vuelve a introducir valores diferentes')
lim_inf = int(input('Límite inferior = '))
lim_sup = int(input('Límite superior = '))
a = int(input('valor a = '))
b = int(input('valor de b = '))
res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
print()
print('Valor de la integral',res[0])

elif opcion == 4:
break









share|improve this question


























    up vote
    1
    down vote

    favorite












    So I want to do a while loop just to calculate the integral of some random functions. The thing is that when I pass opción = 1 it does the first if (good) but when I pass other number it breaks. Obviously, because True = 1 and False = 0. So how can I do it to do the while loop until (1,2,3) until I press 4... Thanks you so much in advance



    while opcion == True:
    if opcion == 1:
    print('Vamos a calcular la siguiente integral:')
    f = a*x + b
    integral = sp.Integral(f, x)
    sp.pprint(integral)
    print()
    print('Que tiene como resultado:')
    sp.pprint(sp.integrate(f,x))
    print()
    print('Introducimos los límites y valores de las'
    ' constantes para caluclarla')
    lim_inf = int(input('Límite inferior = '))
    lim_sup = int(input('Límite superior = '))
    while (lim_inf == lim_sup):
    print('Los límites no pueden ser iguales !! '
    'Vuelve a introducir valores diferentes')
    lim_inf = int(input('Límite inferior = '))
    lim_sup = int(input('Límite superior = '))
    a = int(input('valor a = '))
    b = int(input('valor de b = '))
    res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
    print()
    print('Valor de la integral',res[0])

    elif opcion == 2:
    print('Vamos a calcular la siguiente integral:')
    f = a*x**2 + b*x + c
    integral = sp.Integral(f, x)
    sp.pprint(integral)
    print()
    print('Que tiene como resultado:')
    sp.pprint(sp.integrate(f,x))
    print()
    print('Introducimos los límites y valores de las'
    ' constantes para caluclarla')
    lim_inf = int(input('Límite inferior = '))
    lim_sup = int(input('Límite superior = '))
    while (lim_inf == lim_sup):
    print('Los límites no pueden ser iguales !! '
    'Vuelve a introducir valores diferentes')
    lim_inf = int(input('Límite inferior = '))
    lim_sup = int(input('Límite superior = '))
    a = int(input('valor a = '))
    b = int(input('valor de b = '))
    res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
    print()
    print('Valor de la integral',res[0])

    elif opcion == 3:
    print('Vamos a calcular la siguiente integral:')
    f = a*x**3 + b*x**2 + c*x**2 + d
    integral = sp.Integral(f, x)
    sp.pprint(integral)
    print()
    print('Que tiene como resultado:')
    sp.pprint(sp.integrate(f,x))
    print()
    print('Introducimos los límites y valores de las'
    ' constantes para caluclarla')
    lim_inf = int(input('Límite inferior = '))
    lim_sup = int(input('Límite superior = '))
    while (lim_inf == lim_sup):
    print('Los límites no pueden ser iguales !! '
    'Vuelve a introducir valores diferentes')
    lim_inf = int(input('Límite inferior = '))
    lim_sup = int(input('Límite superior = '))
    a = int(input('valor a = '))
    b = int(input('valor de b = '))
    res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
    print()
    print('Valor de la integral',res[0])

    elif opcion == 4:
    break









    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      So I want to do a while loop just to calculate the integral of some random functions. The thing is that when I pass opción = 1 it does the first if (good) but when I pass other number it breaks. Obviously, because True = 1 and False = 0. So how can I do it to do the while loop until (1,2,3) until I press 4... Thanks you so much in advance



      while opcion == True:
      if opcion == 1:
      print('Vamos a calcular la siguiente integral:')
      f = a*x + b
      integral = sp.Integral(f, x)
      sp.pprint(integral)
      print()
      print('Que tiene como resultado:')
      sp.pprint(sp.integrate(f,x))
      print()
      print('Introducimos los límites y valores de las'
      ' constantes para caluclarla')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      while (lim_inf == lim_sup):
      print('Los límites no pueden ser iguales !! '
      'Vuelve a introducir valores diferentes')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      a = int(input('valor a = '))
      b = int(input('valor de b = '))
      res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
      print()
      print('Valor de la integral',res[0])

      elif opcion == 2:
      print('Vamos a calcular la siguiente integral:')
      f = a*x**2 + b*x + c
      integral = sp.Integral(f, x)
      sp.pprint(integral)
      print()
      print('Que tiene como resultado:')
      sp.pprint(sp.integrate(f,x))
      print()
      print('Introducimos los límites y valores de las'
      ' constantes para caluclarla')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      while (lim_inf == lim_sup):
      print('Los límites no pueden ser iguales !! '
      'Vuelve a introducir valores diferentes')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      a = int(input('valor a = '))
      b = int(input('valor de b = '))
      res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
      print()
      print('Valor de la integral',res[0])

      elif opcion == 3:
      print('Vamos a calcular la siguiente integral:')
      f = a*x**3 + b*x**2 + c*x**2 + d
      integral = sp.Integral(f, x)
      sp.pprint(integral)
      print()
      print('Que tiene como resultado:')
      sp.pprint(sp.integrate(f,x))
      print()
      print('Introducimos los límites y valores de las'
      ' constantes para caluclarla')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      while (lim_inf == lim_sup):
      print('Los límites no pueden ser iguales !! '
      'Vuelve a introducir valores diferentes')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      a = int(input('valor a = '))
      b = int(input('valor de b = '))
      res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
      print()
      print('Valor de la integral',res[0])

      elif opcion == 4:
      break









      share|improve this question













      So I want to do a while loop just to calculate the integral of some random functions. The thing is that when I pass opción = 1 it does the first if (good) but when I pass other number it breaks. Obviously, because True = 1 and False = 0. So how can I do it to do the while loop until (1,2,3) until I press 4... Thanks you so much in advance



      while opcion == True:
      if opcion == 1:
      print('Vamos a calcular la siguiente integral:')
      f = a*x + b
      integral = sp.Integral(f, x)
      sp.pprint(integral)
      print()
      print('Que tiene como resultado:')
      sp.pprint(sp.integrate(f,x))
      print()
      print('Introducimos los límites y valores de las'
      ' constantes para caluclarla')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      while (lim_inf == lim_sup):
      print('Los límites no pueden ser iguales !! '
      'Vuelve a introducir valores diferentes')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      a = int(input('valor a = '))
      b = int(input('valor de b = '))
      res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
      print()
      print('Valor de la integral',res[0])

      elif opcion == 2:
      print('Vamos a calcular la siguiente integral:')
      f = a*x**2 + b*x + c
      integral = sp.Integral(f, x)
      sp.pprint(integral)
      print()
      print('Que tiene como resultado:')
      sp.pprint(sp.integrate(f,x))
      print()
      print('Introducimos los límites y valores de las'
      ' constantes para caluclarla')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      while (lim_inf == lim_sup):
      print('Los límites no pueden ser iguales !! '
      'Vuelve a introducir valores diferentes')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      a = int(input('valor a = '))
      b = int(input('valor de b = '))
      res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
      print()
      print('Valor de la integral',res[0])

      elif opcion == 3:
      print('Vamos a calcular la siguiente integral:')
      f = a*x**3 + b*x**2 + c*x**2 + d
      integral = sp.Integral(f, x)
      sp.pprint(integral)
      print()
      print('Que tiene como resultado:')
      sp.pprint(sp.integrate(f,x))
      print()
      print('Introducimos los límites y valores de las'
      ' constantes para caluclarla')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      while (lim_inf == lim_sup):
      print('Los límites no pueden ser iguales !! '
      'Vuelve a introducir valores diferentes')
      lim_inf = int(input('Límite inferior = '))
      lim_sup = int(input('Límite superior = '))
      a = int(input('valor a = '))
      b = int(input('valor de b = '))
      res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
      print()
      print('Valor de la integral',res[0])

      elif opcion == 4:
      break






      while-loop python-3.6






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 12:56









      Álvaro Romero Mato

      82




      82
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          you should just wrap it into the while true then cause the break as expected and don't depent on option. Use sys to just pass in the opcion as an argument for the script so that 4 will just cause it to break automatically... otherwise if its just generated into the script... you can have opcion generate a 1 by default to begin work.



          import sys
          ...
          opcion = sys.argv[1]
          while True:
          if opcion == 1:
          print('Vamos a calcular la siguiente integral:')
          f = a*x + b
          integral = sp.Integral(f, x)
          sp.pprint(integral)
          print()
          print('Que tiene como resultado:')
          sp.pprint(sp.integrate(f,x))
          print()
          print('Introducimos los límites y valores de las'
          ' constantes para caluclarla')
          lim_inf = int(input('Límite inferior = '))
          lim_sup = int(input('Límite superior = '))
          while (lim_inf == lim_sup):
          print('Los límites no pueden ser iguales !! '
          'Vuelve a introducir valores diferentes')
          lim_inf = int(input('Límite inferior = '))
          lim_sup = int(input('Límite superior = '))
          a = int(input('valor a = '))
          b = int(input('valor de b = '))
          res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
          print()
          print('Valor de la integral',res[0])

          elif opcion == 2:
          print('Vamos a calcular la siguiente integral:')
          f = a*x**2 + b*x + c
          integral = sp.Integral(f, x)
          sp.pprint(integral)
          print()
          print('Que tiene como resultado:')
          sp.pprint(sp.integrate(f,x))
          print()
          print('Introducimos los límites y valores de las'
          ' constantes para caluclarla')
          lim_inf = int(input('Límite inferior = '))
          lim_sup = int(input('Límite superior = '))
          while (lim_inf == lim_sup):
          print('Los límites no pueden ser iguales !! '
          'Vuelve a introducir valores diferentes')
          lim_inf = int(input('Límite inferior = '))
          lim_sup = int(input('Límite superior = '))
          a = int(input('valor a = '))
          b = int(input('valor de b = '))
          res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
          print()
          print('Valor de la integral',res[0])

          elif opcion == 3:
          print('Vamos a calcular la siguiente integral:')
          f = a*x**3 + b*x**2 + c*x**2 + d
          integral = sp.Integral(f, x)
          sp.pprint(integral)
          print()
          print('Que tiene como resultado:')
          sp.pprint(sp.integrate(f,x))
          print()
          print('Introducimos los límites y valores de las'
          ' constantes para caluclarla')
          lim_inf = int(input('Límite inferior = '))
          lim_sup = int(input('Límite superior = '))
          while (lim_inf == lim_sup):
          print('Los límites no pueden ser iguales !! '
          'Vuelve a introducir valores diferentes')
          lim_inf = int(input('Límite inferior = '))
          lim_sup = int(input('Límite superior = '))
          a = int(input('valor a = '))
          b = int(input('valor de b = '))
          res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
          print()
          print('Valor de la integral',res[0])

          elif opcion == 4:
          break





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239177%2fcant-loop-a-while-loop%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            you should just wrap it into the while true then cause the break as expected and don't depent on option. Use sys to just pass in the opcion as an argument for the script so that 4 will just cause it to break automatically... otherwise if its just generated into the script... you can have opcion generate a 1 by default to begin work.



            import sys
            ...
            opcion = sys.argv[1]
            while True:
            if opcion == 1:
            print('Vamos a calcular la siguiente integral:')
            f = a*x + b
            integral = sp.Integral(f, x)
            sp.pprint(integral)
            print()
            print('Que tiene como resultado:')
            sp.pprint(sp.integrate(f,x))
            print()
            print('Introducimos los límites y valores de las'
            ' constantes para caluclarla')
            lim_inf = int(input('Límite inferior = '))
            lim_sup = int(input('Límite superior = '))
            while (lim_inf == lim_sup):
            print('Los límites no pueden ser iguales !! '
            'Vuelve a introducir valores diferentes')
            lim_inf = int(input('Límite inferior = '))
            lim_sup = int(input('Límite superior = '))
            a = int(input('valor a = '))
            b = int(input('valor de b = '))
            res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
            print()
            print('Valor de la integral',res[0])

            elif opcion == 2:
            print('Vamos a calcular la siguiente integral:')
            f = a*x**2 + b*x + c
            integral = sp.Integral(f, x)
            sp.pprint(integral)
            print()
            print('Que tiene como resultado:')
            sp.pprint(sp.integrate(f,x))
            print()
            print('Introducimos los límites y valores de las'
            ' constantes para caluclarla')
            lim_inf = int(input('Límite inferior = '))
            lim_sup = int(input('Límite superior = '))
            while (lim_inf == lim_sup):
            print('Los límites no pueden ser iguales !! '
            'Vuelve a introducir valores diferentes')
            lim_inf = int(input('Límite inferior = '))
            lim_sup = int(input('Límite superior = '))
            a = int(input('valor a = '))
            b = int(input('valor de b = '))
            res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
            print()
            print('Valor de la integral',res[0])

            elif opcion == 3:
            print('Vamos a calcular la siguiente integral:')
            f = a*x**3 + b*x**2 + c*x**2 + d
            integral = sp.Integral(f, x)
            sp.pprint(integral)
            print()
            print('Que tiene como resultado:')
            sp.pprint(sp.integrate(f,x))
            print()
            print('Introducimos los límites y valores de las'
            ' constantes para caluclarla')
            lim_inf = int(input('Límite inferior = '))
            lim_sup = int(input('Límite superior = '))
            while (lim_inf == lim_sup):
            print('Los límites no pueden ser iguales !! '
            'Vuelve a introducir valores diferentes')
            lim_inf = int(input('Límite inferior = '))
            lim_sup = int(input('Límite superior = '))
            a = int(input('valor a = '))
            b = int(input('valor de b = '))
            res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
            print()
            print('Valor de la integral',res[0])

            elif opcion == 4:
            break





            share|improve this answer

























              up vote
              0
              down vote













              you should just wrap it into the while true then cause the break as expected and don't depent on option. Use sys to just pass in the opcion as an argument for the script so that 4 will just cause it to break automatically... otherwise if its just generated into the script... you can have opcion generate a 1 by default to begin work.



              import sys
              ...
              opcion = sys.argv[1]
              while True:
              if opcion == 1:
              print('Vamos a calcular la siguiente integral:')
              f = a*x + b
              integral = sp.Integral(f, x)
              sp.pprint(integral)
              print()
              print('Que tiene como resultado:')
              sp.pprint(sp.integrate(f,x))
              print()
              print('Introducimos los límites y valores de las'
              ' constantes para caluclarla')
              lim_inf = int(input('Límite inferior = '))
              lim_sup = int(input('Límite superior = '))
              while (lim_inf == lim_sup):
              print('Los límites no pueden ser iguales !! '
              'Vuelve a introducir valores diferentes')
              lim_inf = int(input('Límite inferior = '))
              lim_sup = int(input('Límite superior = '))
              a = int(input('valor a = '))
              b = int(input('valor de b = '))
              res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
              print()
              print('Valor de la integral',res[0])

              elif opcion == 2:
              print('Vamos a calcular la siguiente integral:')
              f = a*x**2 + b*x + c
              integral = sp.Integral(f, x)
              sp.pprint(integral)
              print()
              print('Que tiene como resultado:')
              sp.pprint(sp.integrate(f,x))
              print()
              print('Introducimos los límites y valores de las'
              ' constantes para caluclarla')
              lim_inf = int(input('Límite inferior = '))
              lim_sup = int(input('Límite superior = '))
              while (lim_inf == lim_sup):
              print('Los límites no pueden ser iguales !! '
              'Vuelve a introducir valores diferentes')
              lim_inf = int(input('Límite inferior = '))
              lim_sup = int(input('Límite superior = '))
              a = int(input('valor a = '))
              b = int(input('valor de b = '))
              res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
              print()
              print('Valor de la integral',res[0])

              elif opcion == 3:
              print('Vamos a calcular la siguiente integral:')
              f = a*x**3 + b*x**2 + c*x**2 + d
              integral = sp.Integral(f, x)
              sp.pprint(integral)
              print()
              print('Que tiene como resultado:')
              sp.pprint(sp.integrate(f,x))
              print()
              print('Introducimos los límites y valores de las'
              ' constantes para caluclarla')
              lim_inf = int(input('Límite inferior = '))
              lim_sup = int(input('Límite superior = '))
              while (lim_inf == lim_sup):
              print('Los límites no pueden ser iguales !! '
              'Vuelve a introducir valores diferentes')
              lim_inf = int(input('Límite inferior = '))
              lim_sup = int(input('Límite superior = '))
              a = int(input('valor a = '))
              b = int(input('valor de b = '))
              res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
              print()
              print('Valor de la integral',res[0])

              elif opcion == 4:
              break





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                you should just wrap it into the while true then cause the break as expected and don't depent on option. Use sys to just pass in the opcion as an argument for the script so that 4 will just cause it to break automatically... otherwise if its just generated into the script... you can have opcion generate a 1 by default to begin work.



                import sys
                ...
                opcion = sys.argv[1]
                while True:
                if opcion == 1:
                print('Vamos a calcular la siguiente integral:')
                f = a*x + b
                integral = sp.Integral(f, x)
                sp.pprint(integral)
                print()
                print('Que tiene como resultado:')
                sp.pprint(sp.integrate(f,x))
                print()
                print('Introducimos los límites y valores de las'
                ' constantes para caluclarla')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                while (lim_inf == lim_sup):
                print('Los límites no pueden ser iguales !! '
                'Vuelve a introducir valores diferentes')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                a = int(input('valor a = '))
                b = int(input('valor de b = '))
                res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
                print()
                print('Valor de la integral',res[0])

                elif opcion == 2:
                print('Vamos a calcular la siguiente integral:')
                f = a*x**2 + b*x + c
                integral = sp.Integral(f, x)
                sp.pprint(integral)
                print()
                print('Que tiene como resultado:')
                sp.pprint(sp.integrate(f,x))
                print()
                print('Introducimos los límites y valores de las'
                ' constantes para caluclarla')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                while (lim_inf == lim_sup):
                print('Los límites no pueden ser iguales !! '
                'Vuelve a introducir valores diferentes')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                a = int(input('valor a = '))
                b = int(input('valor de b = '))
                res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
                print()
                print('Valor de la integral',res[0])

                elif opcion == 3:
                print('Vamos a calcular la siguiente integral:')
                f = a*x**3 + b*x**2 + c*x**2 + d
                integral = sp.Integral(f, x)
                sp.pprint(integral)
                print()
                print('Que tiene como resultado:')
                sp.pprint(sp.integrate(f,x))
                print()
                print('Introducimos los límites y valores de las'
                ' constantes para caluclarla')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                while (lim_inf == lim_sup):
                print('Los límites no pueden ser iguales !! '
                'Vuelve a introducir valores diferentes')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                a = int(input('valor a = '))
                b = int(input('valor de b = '))
                res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
                print()
                print('Valor de la integral',res[0])

                elif opcion == 4:
                break





                share|improve this answer












                you should just wrap it into the while true then cause the break as expected and don't depent on option. Use sys to just pass in the opcion as an argument for the script so that 4 will just cause it to break automatically... otherwise if its just generated into the script... you can have opcion generate a 1 by default to begin work.



                import sys
                ...
                opcion = sys.argv[1]
                while True:
                if opcion == 1:
                print('Vamos a calcular la siguiente integral:')
                f = a*x + b
                integral = sp.Integral(f, x)
                sp.pprint(integral)
                print()
                print('Que tiene como resultado:')
                sp.pprint(sp.integrate(f,x))
                print()
                print('Introducimos los límites y valores de las'
                ' constantes para caluclarla')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                while (lim_inf == lim_sup):
                print('Los límites no pueden ser iguales !! '
                'Vuelve a introducir valores diferentes')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                a = int(input('valor a = '))
                b = int(input('valor de b = '))
                res = integrate.quad(grad1, lim_inf, lim_sup, args=(a,b))
                print()
                print('Valor de la integral',res[0])

                elif opcion == 2:
                print('Vamos a calcular la siguiente integral:')
                f = a*x**2 + b*x + c
                integral = sp.Integral(f, x)
                sp.pprint(integral)
                print()
                print('Que tiene como resultado:')
                sp.pprint(sp.integrate(f,x))
                print()
                print('Introducimos los límites y valores de las'
                ' constantes para caluclarla')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                while (lim_inf == lim_sup):
                print('Los límites no pueden ser iguales !! '
                'Vuelve a introducir valores diferentes')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                a = int(input('valor a = '))
                b = int(input('valor de b = '))
                res = integrate.quad(grad2, lim_inf, lim_sup, args=(a,b))
                print()
                print('Valor de la integral',res[0])

                elif opcion == 3:
                print('Vamos a calcular la siguiente integral:')
                f = a*x**3 + b*x**2 + c*x**2 + d
                integral = sp.Integral(f, x)
                sp.pprint(integral)
                print()
                print('Que tiene como resultado:')
                sp.pprint(sp.integrate(f,x))
                print()
                print('Introducimos los límites y valores de las'
                ' constantes para caluclarla')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                while (lim_inf == lim_sup):
                print('Los límites no pueden ser iguales !! '
                'Vuelve a introducir valores diferentes')
                lim_inf = int(input('Límite inferior = '))
                lim_sup = int(input('Límite superior = '))
                a = int(input('valor a = '))
                b = int(input('valor de b = '))
                res = integrate.quad(grad3, lim_inf, lim_sup, args=(a,b))
                print()
                print('Valor de la integral',res[0])

                elif opcion == 4:
                break






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 13:03









                Frankenmint

                7341622




                7341622






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239177%2fcant-loop-a-while-loop%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Full-time equivalent

                    Bicuculline

                    さくらももこ