Closed Thread
Results 1 to 4 of 4

Thread: Possible Syntax Error.

  1. #1
    ImTheMessenger's Avatar
    ImTheMessenger is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Virginia
    Posts
    30
    Rep Power
    0

    Possible Syntax Error.

    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
    Code:
    # 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?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Possible Syntax Error.

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

  4. #3
    ImTheMessenger's Avatar
    ImTheMessenger is offline Learning Programmer
    Join Date
    Dec 2009
    Location
    Virginia
    Posts
    30
    Rep Power
    0

    Re: Possible Syntax Error.

    Quote Originally Posted by ZekeDragon View Post
    Code:
    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...

  5. #4
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Possible Syntax Error.

    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.
    Wow I changed my sig!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C++ syntax error?
    By DMK741 in forum C and C++
    Replies: 10
    Last Post: 01-04-2011, 07:41 PM
  2. SQL syntax error
    By Timefly in forum PHP Development
    Replies: 2
    Last Post: 11-02-2010, 06:30 AM
  3. [help]Parse error: syntax error, unexpected $end
    By kiddies in forum PHP Development
    Replies: 3
    Last Post: 07-18-2010, 02:58 PM
  4. Odd syntax error?
    By akashhsaka in forum Python
    Replies: 6
    Last Post: 05-22-2009, 03:29 PM
  5. SQL syntax error
    By reachpradeep in forum Database & Database Programming
    Replies: 2
    Last Post: 10-11-2007, 09:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts