-1

Here's the coding I've done:

from math import *
from time import sleep

def vacation():
    print("Time to plan for a vacation.")

    sleep(1)

    dates = input("Let's start with the dates. What day are you getting there, and what day are you leaving? For formatting, you can use month/day-month/day.")

    sleep(1)

    location = input("Now where are you traveling to?")

    sleep(1)

    ticketCost = input("What is the cost of a two-way ticket to " + location + " and back?")

    sleep(1)

    dayOne = input("What is the cost for at least two meals on the first day?")
    dayTwo = input("What is the cost for at least two meals on the second day?")

    sleep(1)

    hotel = input("What is the name of the hotel you are staying at?")
    hotelCost = input("What is the cost for one night at (the) " + hotel + "?")

    sleep(1)

    print("Vacation! Going to " + location + " for " + dates + ".")
    print("-------------------------------")
    print("Total cost of the trip:")
    print("-------------------------------")

    sleep(1)

    print("Plane Ticket: " + ticketCost)

    sleep(1)

    print("Estimate Cost of Meals (Day One): " + dayOne + ".")
    sleep(1)
    print("Estimate Cost of Meals (Day Two): " + dayTwo + ".")
    sleep(1)
    print("One Night at (the) " + hotel + ": " + hotelCost + ".")
    sleep(1)
    **total = hotelCost + dayOne + dayTwo + ticketCost**
    **totalExtra = total + 50
    print("The total is: " + total + ".")**
    sleep(1)
    print("Make sure you leave some room for souvenirs, pay tolls, and other expenses. Additional $50 is added for this, and that total is: " + totalExtra + ".")
    print("-------------------------------")
    sleep(1)
    print("Enjoy your vacation!")

vacation()

The problem areas are in bold. I do not know what to do, I've tried using int(), str(), and etc in multiple places. The total shouldn't be gibberish (ie, "843290842"). Am I missing something?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Waffles
  • 21
  • 4

1 Answers1

0

The input function returns a string, not an integer. Just cast them everywhere:

dates = int(input("Let's start with the dates. What day are you getting there, and what day are you leaving? For formatting, you can use month/day-month/day."))

etc...

A couple of other points

If you're going to add these all together later consider putting them in a collection instead of just a whole bunch of loose variables. A dictionary would let you keep the names so:

costs = {}
costs['dates'] = int(input("Let's start with the dates. What day are you getting there, and what day are you leaving? For formatting, you can use month/day-month/day."))

At the end you can easily get the total by just looping over the dictionary

total = sum(costs.values())

Just remember to leave out values that are supposed to be strings like hotel, which should probably be called hotel_name instead.

Lastly, you should try out string interpolation (this depends on your Python version but for 3.6+):

"What is the cost for one night at (the) " + hotel + "?"

becomes

f"What is the cost for one night at (the) {hotel}?"
Dan
  • 45,079
  • 17
  • 88
  • 157
  • "TypeError: 'ticketCost' is an invalid keyword argument for this function on line 21" – Waffles Oct 31 '18 at 17:46
  • What should I do now? – Waffles Oct 31 '18 at 17:52
  • You'll need to provide the line of code that produced that error... it sounds like you've both used the wrong kind of brackets – Dan Oct 31 '18 at 17:53
  • nevermind, got it – Waffles Oct 31 '18 at 17:55
  • @Waffles look at where you put `int(` and where I put it... you should only be wrapping your call to `input` in `int`, not the whole assignment – Dan Oct 31 '18 at 17:56
  • New issue: print("Plane Ticket: " + ticketCost) returned with "TypeError: cannot concatenate 'str' and 'int' objects on line 42" – Waffles Oct 31 '18 at 17:57
  • Read the rest of my answer, use string interpolation for that. the bad way to solve it is `print("Plane Ticket: " + str(ticketCost))` the good way is `print(f"Plane Ticket: {ticketCost}")` or `print(f"Plane Ticket: {}".format(ticketCost))` if you're on an older version of python – Dan Oct 31 '18 at 17:59
  • print("The total is: " + total + ".") resulted in "TypeError: cannot concatenate 'str' and 'int' objects on line 54" – Waffles Oct 31 '18 at 18:24