Script that counts quarters, dimes, nickels, and penniesGroup By And Two CountsCross-platform performance and...

What is a term for a function that when called repeatedly, has the same effect as calling once?

In the world of The Matrix, what is "popping"?

How to make sure I'm assertive enough in contact with subordinates?

Is being socially reclusive okay for a graduate student?

Does the US political system, in principle, allow for a no-party system?

Why would the IRS ask for birth certificates or even audit a small tax return?

Integrating function with /; in its definition

The (Easy) Road to Code

Should we avoid writing fiction about historical events without extensive research?

Why is there an extra space when I type "ls" on the Desktop?

Why aren't there more gauls like Obelix?

Does the in-code argument passing conventions used on PDP-11's have a name?

The past tense for the quoting particle って

Using the imperfect indicative vs. subjunctive with si

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

Should I use HTTPS on a domain that will only be used for redirection?

Why are special aircraft used for the carriers in the United States Navy?

Are Wave equations equivalent to Maxwell equations in free space?

Under what conditions would I NOT add my Proficiency Bonus to a Spell Attack Roll (or Saving Throw DC)?

What is better: yes / no radio, or simple checkbox?

Why can't we use freedom of speech and expression to incite people to rebel against government in India?

Learning to quickly identify valid fingering for piano?

The need of reserving one's ability in job interviews

Where is the fallacy here?



Script that counts quarters, dimes, nickels, and pennies


Group By And Two CountsCross-platform performance and statistical information scriptGrouping logs and providing countsCounting single degree vertex removal rounds (from a graph)Let's protect that CLI Python scriptIterative “counting change” implementation in mit-schemeCalculating frequencies of each obs in the dataInfinite monkey theorem demonstration in PythonReturn the amount of Quarters, Dimes, Nickels, and Pennies that you would get from the total amount of changeSimple game of hangman which counts wins and losses













5












$begingroup$


I am learning Python and I wrote a script that counts how many coins you would need for an amount in dollars. I was wondering if I could make any improvements to it.



def change():
amnt = float(input("Enter an amount in USD: "))
quarters = divmod(amnt, 0.25)
print("Quarters: ", quarters[0])
amnt = round(quarters[1], 2)
dimes = divmod(amnt, 0.10)
print("Dimes: ", dimes[0])
amnt = round(dimes[1], 2)
nickels = divmod(amnt, 0.
print("Nickels: ", nickels[0])
amnt = round(nickels[1], 2)
penny = divmod(amnt, 0.01)
print("Pennies", penny[0])
change()









share|improve this question









New contributor




Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    5












    $begingroup$


    I am learning Python and I wrote a script that counts how many coins you would need for an amount in dollars. I was wondering if I could make any improvements to it.



    def change():
    amnt = float(input("Enter an amount in USD: "))
    quarters = divmod(amnt, 0.25)
    print("Quarters: ", quarters[0])
    amnt = round(quarters[1], 2)
    dimes = divmod(amnt, 0.10)
    print("Dimes: ", dimes[0])
    amnt = round(dimes[1], 2)
    nickels = divmod(amnt, 0.
    print("Nickels: ", nickels[0])
    amnt = round(nickels[1], 2)
    penny = divmod(amnt, 0.01)
    print("Pennies", penny[0])
    change()









    share|improve this question









    New contributor




    Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      5












      5








      5


      1



      $begingroup$


      I am learning Python and I wrote a script that counts how many coins you would need for an amount in dollars. I was wondering if I could make any improvements to it.



      def change():
      amnt = float(input("Enter an amount in USD: "))
      quarters = divmod(amnt, 0.25)
      print("Quarters: ", quarters[0])
      amnt = round(quarters[1], 2)
      dimes = divmod(amnt, 0.10)
      print("Dimes: ", dimes[0])
      amnt = round(dimes[1], 2)
      nickels = divmod(amnt, 0.
      print("Nickels: ", nickels[0])
      amnt = round(nickels[1], 2)
      penny = divmod(amnt, 0.01)
      print("Pennies", penny[0])
      change()









      share|improve this question









      New contributor




      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I am learning Python and I wrote a script that counts how many coins you would need for an amount in dollars. I was wondering if I could make any improvements to it.



      def change():
      amnt = float(input("Enter an amount in USD: "))
      quarters = divmod(amnt, 0.25)
      print("Quarters: ", quarters[0])
      amnt = round(quarters[1], 2)
      dimes = divmod(amnt, 0.10)
      print("Dimes: ", dimes[0])
      amnt = round(dimes[1], 2)
      nickels = divmod(amnt, 0.
      print("Nickels: ", nickels[0])
      amnt = round(nickels[1], 2)
      penny = divmod(amnt, 0.01)
      print("Pennies", penny[0])
      change()






      python beginner python-3.x change-making-problem






      share|improve this question









      New contributor




      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 22 hours ago









      200_success

      130k16153419




      130k16153419






      New contributor




      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      Hasan QaziHasan Qazi

      282




      282




      New contributor




      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Hasan Qazi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          9












          $begingroup$

          Separate input from processing. If you want to test your method with a number of different values, you'll have to call change() multiple times, and enter in the value each time. Instead, change the function to accept the amnt, and you can call it many times passing in the amount of cash as an argument:



          def change(amnt):
          # ...


          Working with tuples from divmod is awkward. Python has deconstructing assignment, which will take a returned tuple an assign the members to separate variables:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          print("Quarters: ", quarters)

          dimes, amnt = divmod(round(amnt, 2), 0.10)
          print("Dimes: ", dimes)


          For the last operation, you don't use the remainder, so the "throw-away" variable _ can be used for it:



              pennies, _ = divmod(round(amnt, 2), 0.01)
          print("Pennies: ", pennies)


          If you import this script into another program, you probably don't want the script to immediately run; rather you just want the change(amnt) function to be defined so this other program can call it. This is done by adding a "guard" at the end of the script, which only runs the code if the script is invoked directly:



          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          change(amnt)




          In addition to separating input from processing, you might want to separate the processing from the output:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          dimes, amnt = divmod(amnt, 0.10)
          nickels, amnt = divmod(amnt, 0.05)
          pennies = round(amnt / 0.01, 0)

          return list(map(int, [quarters, dimes, nickels, pennies]))

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))




          Despite attempts to fix rounding errors with things like round(amnt,2), calling change(0.85) returns [3, 0, 1, 5], showing that there wasn't quite enough change to make 2 nickels, but after removing 1 nickel, approximately 5 pennies remained. This is caused by floating point math.



          We can avoid these issues by switching to integer math, based on the number of pennies:



          def change(amnt):
          pennies = round(amnt * 100) # Convert from dollars to pennies

          quarters, pennies = divmod(pennies, 25)
          dimes, pennies = divmod(pennies, 10)
          nickels, pennies = divmod(pennies, 5)

          return quarters, dimes, nickels, pennies

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))


          As mentioned in the comments by @Ilmari, round(...) with only a single argument will round the value to the nearest whole number and return an integer value. When integer values are used with divmod, results are also integers, so switching from dollars-and-cents to integer pennies eliminates the ugly rounding issues.






          share|improve this answer











          $endgroup$













          • $begingroup$
            +1 for everything except your non-PEP8 formatting, even though it does look nice here.
            $endgroup$
            – Graipher
            22 hours ago






          • 1




            $begingroup$
            It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
            $endgroup$
            – Ilmari Karonen
            19 hours ago













          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          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: "196"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          });


          }
          });






          Hasan Qazi is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214888%2fscript-that-counts-quarters-dimes-nickels-and-pennies%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          9












          $begingroup$

          Separate input from processing. If you want to test your method with a number of different values, you'll have to call change() multiple times, and enter in the value each time. Instead, change the function to accept the amnt, and you can call it many times passing in the amount of cash as an argument:



          def change(amnt):
          # ...


          Working with tuples from divmod is awkward. Python has deconstructing assignment, which will take a returned tuple an assign the members to separate variables:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          print("Quarters: ", quarters)

          dimes, amnt = divmod(round(amnt, 2), 0.10)
          print("Dimes: ", dimes)


          For the last operation, you don't use the remainder, so the "throw-away" variable _ can be used for it:



              pennies, _ = divmod(round(amnt, 2), 0.01)
          print("Pennies: ", pennies)


          If you import this script into another program, you probably don't want the script to immediately run; rather you just want the change(amnt) function to be defined so this other program can call it. This is done by adding a "guard" at the end of the script, which only runs the code if the script is invoked directly:



          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          change(amnt)




          In addition to separating input from processing, you might want to separate the processing from the output:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          dimes, amnt = divmod(amnt, 0.10)
          nickels, amnt = divmod(amnt, 0.05)
          pennies = round(amnt / 0.01, 0)

          return list(map(int, [quarters, dimes, nickels, pennies]))

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))




          Despite attempts to fix rounding errors with things like round(amnt,2), calling change(0.85) returns [3, 0, 1, 5], showing that there wasn't quite enough change to make 2 nickels, but after removing 1 nickel, approximately 5 pennies remained. This is caused by floating point math.



          We can avoid these issues by switching to integer math, based on the number of pennies:



          def change(amnt):
          pennies = round(amnt * 100) # Convert from dollars to pennies

          quarters, pennies = divmod(pennies, 25)
          dimes, pennies = divmod(pennies, 10)
          nickels, pennies = divmod(pennies, 5)

          return quarters, dimes, nickels, pennies

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))


          As mentioned in the comments by @Ilmari, round(...) with only a single argument will round the value to the nearest whole number and return an integer value. When integer values are used with divmod, results are also integers, so switching from dollars-and-cents to integer pennies eliminates the ugly rounding issues.






          share|improve this answer











          $endgroup$













          • $begingroup$
            +1 for everything except your non-PEP8 formatting, even though it does look nice here.
            $endgroup$
            – Graipher
            22 hours ago






          • 1




            $begingroup$
            It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
            $endgroup$
            – Ilmari Karonen
            19 hours ago


















          9












          $begingroup$

          Separate input from processing. If you want to test your method with a number of different values, you'll have to call change() multiple times, and enter in the value each time. Instead, change the function to accept the amnt, and you can call it many times passing in the amount of cash as an argument:



          def change(amnt):
          # ...


          Working with tuples from divmod is awkward. Python has deconstructing assignment, which will take a returned tuple an assign the members to separate variables:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          print("Quarters: ", quarters)

          dimes, amnt = divmod(round(amnt, 2), 0.10)
          print("Dimes: ", dimes)


          For the last operation, you don't use the remainder, so the "throw-away" variable _ can be used for it:



              pennies, _ = divmod(round(amnt, 2), 0.01)
          print("Pennies: ", pennies)


          If you import this script into another program, you probably don't want the script to immediately run; rather you just want the change(amnt) function to be defined so this other program can call it. This is done by adding a "guard" at the end of the script, which only runs the code if the script is invoked directly:



          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          change(amnt)




          In addition to separating input from processing, you might want to separate the processing from the output:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          dimes, amnt = divmod(amnt, 0.10)
          nickels, amnt = divmod(amnt, 0.05)
          pennies = round(amnt / 0.01, 0)

          return list(map(int, [quarters, dimes, nickels, pennies]))

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))




          Despite attempts to fix rounding errors with things like round(amnt,2), calling change(0.85) returns [3, 0, 1, 5], showing that there wasn't quite enough change to make 2 nickels, but after removing 1 nickel, approximately 5 pennies remained. This is caused by floating point math.



          We can avoid these issues by switching to integer math, based on the number of pennies:



          def change(amnt):
          pennies = round(amnt * 100) # Convert from dollars to pennies

          quarters, pennies = divmod(pennies, 25)
          dimes, pennies = divmod(pennies, 10)
          nickels, pennies = divmod(pennies, 5)

          return quarters, dimes, nickels, pennies

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))


          As mentioned in the comments by @Ilmari, round(...) with only a single argument will round the value to the nearest whole number and return an integer value. When integer values are used with divmod, results are also integers, so switching from dollars-and-cents to integer pennies eliminates the ugly rounding issues.






          share|improve this answer











          $endgroup$













          • $begingroup$
            +1 for everything except your non-PEP8 formatting, even though it does look nice here.
            $endgroup$
            – Graipher
            22 hours ago






          • 1




            $begingroup$
            It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
            $endgroup$
            – Ilmari Karonen
            19 hours ago
















          9












          9








          9





          $begingroup$

          Separate input from processing. If you want to test your method with a number of different values, you'll have to call change() multiple times, and enter in the value each time. Instead, change the function to accept the amnt, and you can call it many times passing in the amount of cash as an argument:



          def change(amnt):
          # ...


          Working with tuples from divmod is awkward. Python has deconstructing assignment, which will take a returned tuple an assign the members to separate variables:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          print("Quarters: ", quarters)

          dimes, amnt = divmod(round(amnt, 2), 0.10)
          print("Dimes: ", dimes)


          For the last operation, you don't use the remainder, so the "throw-away" variable _ can be used for it:



              pennies, _ = divmod(round(amnt, 2), 0.01)
          print("Pennies: ", pennies)


          If you import this script into another program, you probably don't want the script to immediately run; rather you just want the change(amnt) function to be defined so this other program can call it. This is done by adding a "guard" at the end of the script, which only runs the code if the script is invoked directly:



          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          change(amnt)




          In addition to separating input from processing, you might want to separate the processing from the output:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          dimes, amnt = divmod(amnt, 0.10)
          nickels, amnt = divmod(amnt, 0.05)
          pennies = round(amnt / 0.01, 0)

          return list(map(int, [quarters, dimes, nickels, pennies]))

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))




          Despite attempts to fix rounding errors with things like round(amnt,2), calling change(0.85) returns [3, 0, 1, 5], showing that there wasn't quite enough change to make 2 nickels, but after removing 1 nickel, approximately 5 pennies remained. This is caused by floating point math.



          We can avoid these issues by switching to integer math, based on the number of pennies:



          def change(amnt):
          pennies = round(amnt * 100) # Convert from dollars to pennies

          quarters, pennies = divmod(pennies, 25)
          dimes, pennies = divmod(pennies, 10)
          nickels, pennies = divmod(pennies, 5)

          return quarters, dimes, nickels, pennies

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))


          As mentioned in the comments by @Ilmari, round(...) with only a single argument will round the value to the nearest whole number and return an integer value. When integer values are used with divmod, results are also integers, so switching from dollars-and-cents to integer pennies eliminates the ugly rounding issues.






          share|improve this answer











          $endgroup$



          Separate input from processing. If you want to test your method with a number of different values, you'll have to call change() multiple times, and enter in the value each time. Instead, change the function to accept the amnt, and you can call it many times passing in the amount of cash as an argument:



          def change(amnt):
          # ...


          Working with tuples from divmod is awkward. Python has deconstructing assignment, which will take a returned tuple an assign the members to separate variables:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          print("Quarters: ", quarters)

          dimes, amnt = divmod(round(amnt, 2), 0.10)
          print("Dimes: ", dimes)


          For the last operation, you don't use the remainder, so the "throw-away" variable _ can be used for it:



              pennies, _ = divmod(round(amnt, 2), 0.01)
          print("Pennies: ", pennies)


          If you import this script into another program, you probably don't want the script to immediately run; rather you just want the change(amnt) function to be defined so this other program can call it. This is done by adding a "guard" at the end of the script, which only runs the code if the script is invoked directly:



          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          change(amnt)




          In addition to separating input from processing, you might want to separate the processing from the output:



          def change(amnt):
          quarters, amnt = divmod(amnt, 0.25)
          dimes, amnt = divmod(amnt, 0.10)
          nickels, amnt = divmod(amnt, 0.05)
          pennies = round(amnt / 0.01, 0)

          return list(map(int, [quarters, dimes, nickels, pennies]))

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))




          Despite attempts to fix rounding errors with things like round(amnt,2), calling change(0.85) returns [3, 0, 1, 5], showing that there wasn't quite enough change to make 2 nickels, but after removing 1 nickel, approximately 5 pennies remained. This is caused by floating point math.



          We can avoid these issues by switching to integer math, based on the number of pennies:



          def change(amnt):
          pennies = round(amnt * 100) # Convert from dollars to pennies

          quarters, pennies = divmod(pennies, 25)
          dimes, pennies = divmod(pennies, 10)
          nickels, pennies = divmod(pennies, 5)

          return quarters, dimes, nickels, pennies

          if __name__ == '__main__':
          amnt = float(input("Enter an amount in USD: "))
          quarters, dimes, nickels, pennies = change(amnt)
          print("{} quarters, {} dimes, {} nickels, {} pennies".format(
          quarters, dimes, nickels, pennies))


          As mentioned in the comments by @Ilmari, round(...) with only a single argument will round the value to the nearest whole number and return an integer value. When integer values are used with divmod, results are also integers, so switching from dollars-and-cents to integer pennies eliminates the ugly rounding issues.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered yesterday









          AJNeufeldAJNeufeld

          5,8541420




          5,8541420












          • $begingroup$
            +1 for everything except your non-PEP8 formatting, even though it does look nice here.
            $endgroup$
            – Graipher
            22 hours ago






          • 1




            $begingroup$
            It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
            $endgroup$
            – Ilmari Karonen
            19 hours ago




















          • $begingroup$
            +1 for everything except your non-PEP8 formatting, even though it does look nice here.
            $endgroup$
            – Graipher
            22 hours ago






          • 1




            $begingroup$
            It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
            $endgroup$
            – Ilmari Karonen
            19 hours ago


















          $begingroup$
          +1 for everything except your non-PEP8 formatting, even though it does look nice here.
          $endgroup$
          – Graipher
          22 hours ago




          $begingroup$
          +1 for everything except your non-PEP8 formatting, even though it does look nice here.
          $endgroup$
          – Graipher
          22 hours ago




          1




          1




          $begingroup$
          It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
          $endgroup$
          – Ilmari Karonen
          19 hours ago






          $begingroup$
          It might be worth noting that the behavior of single-argument round() autoconverting floats to ints is specific to Python 3. In Python 2, you'd need to explicitly write pennies = int(round(amnt * 100)) if you want the results to be ints. (Of course, using an explicit int() here is OK in Python 3 too, just redundant.)
          $endgroup$
          – Ilmari Karonen
          19 hours ago












          Hasan Qazi is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Hasan Qazi is a new contributor. Be nice, and check out our Code of Conduct.













          Hasan Qazi is a new contributor. Be nice, and check out our Code of Conduct.












          Hasan Qazi is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • 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.


          Use MathJax to format equations. MathJax reference.


          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%2fcodereview.stackexchange.com%2fquestions%2f214888%2fscript-that-counts-quarters-dimes-nickels-and-pennies%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

          VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

          Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

          looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...