0

This is my code:

def trip(nights):
    return 140 * nights

def plane_cost(ride):
    if ride == "London":
        return 220
    elif ride == "Rome":
        return 200
    elif ride == "Glascow":
        return 185

def car_rental(days):
    cost = 20 * days
    if days >= 7:
        cost = cost - 25
    if days >= 3:
        cost = cost - 10
    return cost

def tripcost(ride, days, spending_pounds):
    trip(days) + plane_cost(ride) + car_rental(days) + spending_pounds

print tripcost("London", 5, 500)

Was wondering why the word tripcost (marked in bold) was shown to be a syntax error when I loaded it in idlE?

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
L. John
  • 39
  • 6
  • Possible duplicate of [How do I print bold text in Python?](http://stackoverflow.com/questions/8924173/how-do-i-print-bold-text-in-python) – JRazor May 07 '16 at 00:16
  • 3
    I bet TextWrangler is Python 2 and your IDE is connected to an installation of Python 3. Is that the case? Try changing that last line to `print(tripcost("London", 5, 500))`. – TigerhawkT3 May 07 '16 at 00:16
  • 2
    @JRazor - I think OP just has asterisks to point out the line with the error. Nothing else in the question makes any indication of wanting bold text. – TigerhawkT3 May 07 '16 at 00:17
  • Please [edit] your post and add the **full text** of the syntax error. – MattDMo May 07 '16 at 00:54
  • Unless an IDE does something extra, which IDLE does not, SyntaxErrors come from the python x.y parser/compiler. Similarly, the editor used is irrelevant, unless it changes what you type, which IDLE also does not. If the report is accurate, this must be a 2 versus 3 syntax change issue. – Terry Jan Reedy May 07 '16 at 02:59
  • Side note: Your `tripcost` function is missing a `return` statement. – Aran-Fey May 07 '16 at 06:48
  • The problem is that in Python 3, `print` is a function, not a statement. Just as `str 4` is invalid syntax, so is `print tripcost(...)`. You need to add the parentheses. In this case, it isn't necessary to change anything for Python 2, but usually if you want to maintain backwards-compatability, you should put `from __future__ import print_function` at the top of the file. – zondo May 07 '16 at 10:42

1 Answers1

0

Try to add at the beginning of the script from __future__ import print_function and change print tripcost("London", 5, 500) on print(tripcost("London", 5, 500))

Sergey Gornostaev
  • 7,596
  • 3
  • 27
  • 39