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
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?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")
This line is missing a closing parenthesis at the end. That's causing your syntax error.Code:rent = int(raw_input(" Manhattan Apartment : ")
Wow I changed my sig!
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!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks