Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Possible Syntax Error.

syntax syntax error

  • Please log in to reply
3 replies to this topic

#1 ImTheMessenger

ImTheMessenger

    CC Regular

  • Just Joined
  • PipPipPip
  • 29 posts

Posted 22 January 2010 - 07:49 PM

again , i'm using an example from an e book i've been reading to study python however this time i'm flat out confused
# Trust Fund Baby - GOOD
# Demonstrates a logical error
#  ~My Name~ 1/12/10

print \
"""

			Trust Fund Baby
	Totals your monthly spending so that your trust fund doesn't run out
	(and your forced to get  real job)
	
	Please enter the requested, monthly costs. Since you're rich, ignore pennies
	and use only dollar amounts.
	
"""

car = raw_input("Lamorghini Tune-Ups : ")
car = int(car)
jet = int(raw_input("Private Jet Rental Cost : "))
rent = int(raw_input(" Manhattan Apartment : ")
gifts = int(raw_input("Gifts : "))
food = int(raw_input("Dining Out : "))
staff = int(raw_input("Staff(butlers, chef, driver, assistant): "))
guru = int(raw_input("Personal Guru and Coach: "))
games = int(raw_input("Computer Games : "))
total = car + rent + gifts + food + staff + guru + games

print "\nGrandTotal: ", + total

raw_input ("\n\nPress the Enter Key to Exit")
ok at first look it's pretty much all right.. a nice example to fix the previous example which didn't inclu]de the () around raw_input but when i run the module i get a syntax error . This time it was gifts, but yesterday it jet, and al though i constantly rename the variables i still get syntax error.. so does any one know why?
  • 0

#2 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 January 2010 - 07:54 PM

rent = int(raw_input(" Manhattan Apartment : ")
This line is missing a closing parenthesis at the end. That's causing your syntax error.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#3 ImTheMessenger

ImTheMessenger

    CC Regular

  • Just Joined
  • PipPipPip
  • 29 posts

Posted 22 January 2010 - 08:07 PM

rent = int(raw_input(" Manhattan Apartment : ")
This line is missing a closing parenthesis at the end. That's causing your syntax error.


Thanks! however..still don't see why the IDLE would say that some other line had the syntax error but not the one that did...
  • 0

#4 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 January 2010 - 08:40 PM

Python has implicit line extensions when you use parenthesis, so by having an additional open parenthesis running Python assumed that the next line was included in the last line's command. Essentially, Python did NOT interpret the enter as a command separation because there was still an open parenthesis pending!

So, when Python encountered the next line (gifts = raw_input), that caused a syntax error. When you close the parenthesis on the line above it, it then separates the two lines into two separate commands and performs as expected.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?





Also tagged with one or more of these keywords: syntax, syntax error

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download