Jun-06-2017, 03:01 PM
(This post was last modified: Jun-06-2017, 03:19 PM by bsullivan1983.)
(Jun-06-2017, 01:35 PM)sparkz_alot Wrote: Seems like a bit of an obscure solution, as I don't know anyone who would write out ten thousand as 10_000
Remember that an integer is a whole number, so if your user enters '10000.5' you will also receive a ValueError. To avoid this, you could usefloat(input())
rather thanint(input())
, this will allow you to accept both whole numbers and decimal numbers.
As to the comma, you will no doubt be taught how to handle errors using 'try/except' clauses in future lessons.
One final thing, this
print( "Number of acres: " + format(landSize, ".2f") )would be better written as:
print("Number of acres: {:.2f}".format(landSize))
Thank you for the suggestion! I don't remember { being discussed, but if it was and I overlooked it I'll consider the change. This is our first out of 3 programs due this week. I don't want to be adding things that aren't in the current covered material so that I'm not accused of plagiarism or anything.
I took both suggestions into consideration and made the changes. Float() does allow the user to input a decimal number, but the output doesn't change. For example, if I input "43560" I get "1" as expected. If I enter 43560.5, the output is still "1." Now, if I enter a whole number that is not exactly one acre, say "90000," I get 2.07. What's the reasoning behind this?