Getting the hang of Python

Following a Python video on Youtube, and think I am doing pretty good so far. Finally got the following compacted as much as I can do for now, but really happy with it.

calculation_to_units = 24
name_of_unit = "hours"

def days_to_units(number_of_days):
    if number_of_days > 0:
        return f"{number_of_days} days are {number_of_days * calculation_to_units} {name_of_unit}"
    else:
        return "You did not enter a positive integer..."

def validate_and_execute():
    try:
        days_entry = int(input("Enter the number of days: "))
        print(days_to_units(days_entry))
    except ValueError:
        print("Please enter a positive integer value...")

validate_and_execute()
Code language: Python (python)

Leave a Comment

one × five =