Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error
#8
(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   Dodgy

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 use float(input()) rather than int(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?
Reply


Messages In This Thread
Syntax Error - by bsullivan1983 - Jun-06-2017, 02:46 AM
RE: Syntax Error - by wavic - Jun-06-2017, 03:27 AM
RE: Syntax Error - by bsullivan1983 - Jun-06-2017, 03:52 AM
RE: Syntax Error - by Larz60+ - Jun-06-2017, 04:24 AM
RE: Syntax Error - by bsullivan1983 - Jun-06-2017, 04:59 AM
RE: Syntax Error - by wavic - Jun-06-2017, 06:36 AM
RE: Syntax Error - by sparkz_alot - Jun-06-2017, 01:35 PM
RE: Syntax Error - by bsullivan1983 - Jun-06-2017, 03:01 PM
RE: Syntax Error - by wavic - Jun-06-2017, 04:56 PM
RE: Syntax Error - by nilamo - Jun-06-2017, 05:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,519 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 2,119 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,144 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 2,106 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 3,547 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 3,469 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 4,198 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,605 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 2,570 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,194 Oct-19-2019, 01:40 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020