RagingTaurus
RagingTaurus

Reputation: 21

How to set up functions

I am new to Stack Overflow, so sorry if this is a bad format. I am not sure how to get this program up and running with multiple functions. I'm not asking for my homework to be done for me. I just would like to know how to call functions or if you can point me in the right direction to get this code running, thank you!

from datetime import datetime

mph = 0

def main():
    print("Arrival Time Estimator\n")


def get_departure_date(arrival_time):
    while True:
        date_str = input("Enter departure date (YYYY-MM-DD): ")
        try:
            departure_date = datetime.strptime(date_str, "%Y-%m-%d")
        except ValueError:
            print("Invalid date format. Try again. ")
            continue

        if departure_date <= get_departure_time():
            print("Departure date must be after arrival date. " +
                  "Try again.")
            continue
        else:
            return departure_date

def get_departure_time():
    while True:
        time_str = input("Enter departure time (HH:MM AM/PM): ")
        try:
            depart_time = datetime.strptime(time_str, "%H-%M %p")
        except ValueError: 
            print("Invalid date format. Try again.")
            continue

        now = datetime.now
        arrivaldate = get_departure_time() + (miles / mph)
        today = datetime(now.year, now.month, now.day)
        if depart_time < today:
            print("Arrival date must be today or later. Try again.")
            continue
        else:
            return arrival()

def arrival():
    miles = input("Enter miles:  ")
    mph = input("Enter miles per hour  ")
    arrivaldate = get_departure_time() + (miles / mph)

Upvotes: 0

Views: 58

Answers (1)

Ryanc88
Ryanc88

Reputation: 192

To call a python function, you use the name of the function. For instance, If your function is:

def arrival():
    miles = input("Enter miles:  ")
    mph = input("Enter miles per hour  ")
    arrivaldate = get_departure_time() + (miles / mph)

You can use it by calling

arrival()

Upvotes: 2

Related Questions