VACATION: Wanted to experiment a bit but I run into syntax problems


#1

I wanted to see if I could make the programm take valuew from the user, check if they are they are usable values and then calculate the vacaton cost on its own… This is the code I came up with. Thank you in advance if you can find the error/errors.

                                        CODE STARTS HERE:
city = raw_input("Hello, and welcome to our travel Agency! With us, you can go around the world. At the moment, we can offer you only three destinations: 'Athens', 'Stockholm' and'Prague'. Please choose one of them: ")
days = input("OK! So you want to travel to" + city +"! Now you have to tell us how many days you want to stay at" + city ": ")
extra_money = input("Please insert the ammount of money you are going to have with you, so that we can calculate how mych wou will spend on yor trip: "
nights = days - 1                    
def plane_price(city):
    if city :
        return 165
    elif city == "Stockholm":
        return 220
    elif city == "Prague"
        return 182
    else:
        return "Error. You didn't choose one from the available destinations."
def hotel_cost(nights):
    if days >0 and days.isdigit() and city== "Athens":
       return 120 * nights
    elif days >0 and days.isdigit() and city== "Stockholm":
         return (140 * nights)-5*nights
    elif days >0 and days.isdigit() and city== "Prague":
         return (125*nights)- 5*nights

    else:
         return "Error. Please input the number of days in digits"
def car_cost(days):
    if days >0 and days.isdigit():
       cost = 80*days
                    if days >=7:
                    cost -=55
                    elif days >=3:
                    cost-= 26
       return cost
     else:
          return "Error. Please input the number of days in digits"
def total_costs(city, nights,days,etra_money):
     if days >=10:
       return plane_ride(city)+hotel_cost(nights)+car_cost(days)+extra_money-700             
     elif  days>=5:              
       return plane_ride(city)+hotel_cost(nights)+car_cost(days)+extra_money-350
     elif days >=3:
         return plane_ride(city)+hotel_cost(nights)+car_cost(days)+extra_money-200
    print "Your total cost for your trip is: " + `total_costs(city, nights,days,etra_money)`

#2

you can’t use + string concatenation within input(), if we look at the documentation:

https://docs.python.org/2/library/functions.html#input

you can see that input() only has a single parameter. You could use string formatting

Be aware that input() evaluates the users input as code, allowing them to inject code into your program, which is quite a security risk


#4

This line raises a SyntaxError

days = input("OK! So you want to travel to" + city +"! Now you have to tell us how many days you want to stay at" + city ": ")

It is missing a + operator after the second occurrence of city.

Follow @stetim94’s advice. Do not use the input function in Python 2. Use raw_input instead.

In Python 3, use input because in that version it replaces raw_input.


#5

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