Syntax error on external python


#1

hi guys, this is the code

def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city):
if city == “Charlotte”:
return 183
elif city == “Tampa”:
return 220
elif city == “Pittsburgh”:
return 222
elif city == “Los Angeles”:
return 475

def rental_car_cost(days):
cost = days * 40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost

def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money

print trip_cost(“Los Angeles”, 5, 600)

everything went well on this site with python but I noticed that a lot of codes that I learn to write over here, aren’t the same at IDLE python or on visual studio and they return me syntax error almost everytime. why is that?? shouldn’t it all be the same?


#2

Python is sensitive to spacing. That may be the source of problems if you are cutting and pasting.

There also may be differences in version numbers. Which, from what I understand is 2.7 on this site.

To find out on the other products this code may be useful:

import sys
print (sys.version) # need parenthesis in python 3

While those reasons may not be the source of your syntax error, they may be. My first instinct is a spacing difference causing the issue.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.