2

I'm learning Python and I have finished my first program and I have already turned it into a .exe using py2exe.

When the program finishes, you are asked a question to either run the program again, or exit it. The thing is that if I run the program again, I can see what I did before. Instead, I want to erase all what I did before and run it as if it was the first time. I'd really appreciate.

Here's the code:

def main():
    days = input("Write how many days you will be on vacation: ")
    city = input("Write the city in which you will be staying at: ")
    expenses = input("Write how much money you will be carrying for expenses (US$): ")

    def hotelCost(days):
        days = int(days)
        return 140*days

    hotelCost(days)

    def flightCost(city):
        if city == "Charlotte" or city == "charlotte":
            return 183
        elif city == "Tempa" or city == "tempa":
            return 220
        elif city == "Pittsburgh" or city == "pittsburgh":
            return 222
        elif city == "Los Angeles" or city == "los angeles":
            return 475
        else:
            print ("Invalid destination")

    flightCost(city)

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

    carCost(days)

    def totalCost():
        overallCost = hotelCost(days) + flightCost(city) + carCost(days)
        overallCost = str(overallCost)
        print ("\nThe total cost of your trip is $" + overallCost)

    totalCost()

    def again():
        yesNo = input("\nWould you like to calculate the cost of another trip? (y/n)\n")

        if yesNo == "y":            
            print ("\n")
            main()

    again()

main()
braX
  • 11,506
  • 5
  • 20
  • 33
Fede Couti
  • 281
  • 2
  • 3
  • 13

0 Answers0