TypeError: unsupported operand type(s) for /: 'str' and 'str'











up vote
4
down vote

favorite
1












name = input('Enter name here:')
pyc = input('enter pyc :')
tpy = input('enter tpy:')
percent = (pyc / tpy) * 100;
print (percent)
input('press enter to quit')


whenever i run this program i get this



TypeError: unsupported operand type(s) for /: 'str' and 'str'


what can i do to divide pyc by tpy?










share|improve this question


























    up vote
    4
    down vote

    favorite
    1












    name = input('Enter name here:')
    pyc = input('enter pyc :')
    tpy = input('enter tpy:')
    percent = (pyc / tpy) * 100;
    print (percent)
    input('press enter to quit')


    whenever i run this program i get this



    TypeError: unsupported operand type(s) for /: 'str' and 'str'


    what can i do to divide pyc by tpy?










    share|improve this question
























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      name = input('Enter name here:')
      pyc = input('enter pyc :')
      tpy = input('enter tpy:')
      percent = (pyc / tpy) * 100;
      print (percent)
      input('press enter to quit')


      whenever i run this program i get this



      TypeError: unsupported operand type(s) for /: 'str' and 'str'


      what can i do to divide pyc by tpy?










      share|improve this question













      name = input('Enter name here:')
      pyc = input('enter pyc :')
      tpy = input('enter tpy:')
      percent = (pyc / tpy) * 100;
      print (percent)
      input('press enter to quit')


      whenever i run this program i get this



      TypeError: unsupported operand type(s) for /: 'str' and 'str'


      what can i do to divide pyc by tpy?







      python typeerror operand






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 5 '13 at 22:52









      Deric miller

      27126




      27126
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          11
          down vote



          accepted










          By turning them into integers instead:



          percent = (int(pyc) / int(tpy)) * 100;


          In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().






          share|improve this answer

















          • 4




            Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
            – Gareth Latty
            Mar 5 '13 at 22:54




















          up vote
          5
          down vote













          The first thing you should do is learn to read error messages. What does it tell you -- that you can't use two strings with the divide operator.



          So, ask yourself why they are strings and how do you make them not-strings. They are strings because all input is done via strings. And the way to make then not-strings is to convert them.



          One way to convert a string to an integer is to use the int function. For example:



          percent = (int(pyc) / int(tpy)) * 100





          share|improve this answer




























            up vote
            0
            down vote













            I would have written:



            percent = 100
            while True:
            try:
            pyc = int(input('enter pyc :'))
            tpy = int(input('enter tpy:'))
            percent = (pyc / tpy) * percent
            break
            except ZeroDivisionError as detail:
            print 'Handling run-time error:', detail





            share|improve this answer





















            • thanks, im new to programming and i never would have known to do this
              – Deric miller
              Mar 7 '13 at 0:12










            • If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
              – abarnert
              Sep 19 '13 at 20:02











            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%2f15235703%2ftypeerror-unsupported-operand-types-for-str-and-str%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            11
            down vote



            accepted










            By turning them into integers instead:



            percent = (int(pyc) / int(tpy)) * 100;


            In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().






            share|improve this answer

















            • 4




              Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
              – Gareth Latty
              Mar 5 '13 at 22:54

















            up vote
            11
            down vote



            accepted










            By turning them into integers instead:



            percent = (int(pyc) / int(tpy)) * 100;


            In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().






            share|improve this answer

















            • 4




              Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
              – Gareth Latty
              Mar 5 '13 at 22:54















            up vote
            11
            down vote



            accepted







            up vote
            11
            down vote



            accepted






            By turning them into integers instead:



            percent = (int(pyc) / int(tpy)) * 100;


            In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().






            share|improve this answer












            By turning them into integers instead:



            percent = (int(pyc) / int(tpy)) * 100;


            In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 5 '13 at 22:53









            Martijn Pieters

            695k12924042245




            695k12924042245








            • 4




              Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
              – Gareth Latty
              Mar 5 '13 at 22:54
















            • 4




              Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
              – Gareth Latty
              Mar 5 '13 at 22:54










            4




            4




            Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
            – Gareth Latty
            Mar 5 '13 at 22:54






            Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers.
            – Gareth Latty
            Mar 5 '13 at 22:54














            up vote
            5
            down vote













            The first thing you should do is learn to read error messages. What does it tell you -- that you can't use two strings with the divide operator.



            So, ask yourself why they are strings and how do you make them not-strings. They are strings because all input is done via strings. And the way to make then not-strings is to convert them.



            One way to convert a string to an integer is to use the int function. For example:



            percent = (int(pyc) / int(tpy)) * 100





            share|improve this answer

























              up vote
              5
              down vote













              The first thing you should do is learn to read error messages. What does it tell you -- that you can't use two strings with the divide operator.



              So, ask yourself why they are strings and how do you make them not-strings. They are strings because all input is done via strings. And the way to make then not-strings is to convert them.



              One way to convert a string to an integer is to use the int function. For example:



              percent = (int(pyc) / int(tpy)) * 100





              share|improve this answer























                up vote
                5
                down vote










                up vote
                5
                down vote









                The first thing you should do is learn to read error messages. What does it tell you -- that you can't use two strings with the divide operator.



                So, ask yourself why they are strings and how do you make them not-strings. They are strings because all input is done via strings. And the way to make then not-strings is to convert them.



                One way to convert a string to an integer is to use the int function. For example:



                percent = (int(pyc) / int(tpy)) * 100





                share|improve this answer












                The first thing you should do is learn to read error messages. What does it tell you -- that you can't use two strings with the divide operator.



                So, ask yourself why they are strings and how do you make them not-strings. They are strings because all input is done via strings. And the way to make then not-strings is to convert them.



                One way to convert a string to an integer is to use the int function. For example:



                percent = (int(pyc) / int(tpy)) * 100






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 5 '13 at 22:53









                Bryan Oakley

                210k21248408




                210k21248408






















                    up vote
                    0
                    down vote













                    I would have written:



                    percent = 100
                    while True:
                    try:
                    pyc = int(input('enter pyc :'))
                    tpy = int(input('enter tpy:'))
                    percent = (pyc / tpy) * percent
                    break
                    except ZeroDivisionError as detail:
                    print 'Handling run-time error:', detail





                    share|improve this answer





















                    • thanks, im new to programming and i never would have known to do this
                      – Deric miller
                      Mar 7 '13 at 0:12










                    • If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
                      – abarnert
                      Sep 19 '13 at 20:02















                    up vote
                    0
                    down vote













                    I would have written:



                    percent = 100
                    while True:
                    try:
                    pyc = int(input('enter pyc :'))
                    tpy = int(input('enter tpy:'))
                    percent = (pyc / tpy) * percent
                    break
                    except ZeroDivisionError as detail:
                    print 'Handling run-time error:', detail





                    share|improve this answer





















                    • thanks, im new to programming and i never would have known to do this
                      – Deric miller
                      Mar 7 '13 at 0:12










                    • If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
                      – abarnert
                      Sep 19 '13 at 20:02













                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    I would have written:



                    percent = 100
                    while True:
                    try:
                    pyc = int(input('enter pyc :'))
                    tpy = int(input('enter tpy:'))
                    percent = (pyc / tpy) * percent
                    break
                    except ZeroDivisionError as detail:
                    print 'Handling run-time error:', detail





                    share|improve this answer












                    I would have written:



                    percent = 100
                    while True:
                    try:
                    pyc = int(input('enter pyc :'))
                    tpy = int(input('enter tpy:'))
                    percent = (pyc / tpy) * percent
                    break
                    except ZeroDivisionError as detail:
                    print 'Handling run-time error:', detail






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 6 '13 at 2:49









                    Kovalchuk

                    315




                    315












                    • thanks, im new to programming and i never would have known to do this
                      – Deric miller
                      Mar 7 '13 at 0:12










                    • If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
                      – abarnert
                      Sep 19 '13 at 20:02


















                    • thanks, im new to programming and i never would have known to do this
                      – Deric miller
                      Mar 7 '13 at 0:12










                    • If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
                      – abarnert
                      Sep 19 '13 at 20:02
















                    thanks, im new to programming and i never would have known to do this
                    – Deric miller
                    Mar 7 '13 at 0:12




                    thanks, im new to programming and i never would have known to do this
                    – Deric miller
                    Mar 7 '13 at 0:12












                    If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
                    – abarnert
                    Sep 19 '13 at 20:02




                    If you're going to add in error handling, you probably want an except ValueError clause to handle invalid inputs…
                    – abarnert
                    Sep 19 '13 at 20:02


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15235703%2ftypeerror-unsupported-operand-types-for-str-and-str%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    RAC Tourist Trophy