Free time calculator I started learning Python 2 about a week ago, using Codecademy and Stack Overflow answers to help me learn. I wrote a code to calculate the user's free time based on user sleep and work time. It also lets the user decide whether to see percentage of free time. It's not fancy; I never intend to actually use it. It works the way I want it to.

I'm looking for feedback on how I wrote this code. What should I have done differently?

print "The program is operating."

def sleep(time):
  sleep_hours = float(raw_input("How many hours do you sleep a night?: "))
  return time - sleep_hours

def work(time):
 work_hours = float(raw_input("How many hours do you work each weekday?: "))
 time -= work_hours
 return time

def see_percent():
  reply = raw_input("Would you like to know the percent of your waking time is free time? (Y/N): ").lower()
  if reply == "y":
    print percent_round + "%."
  elif reply == "n":
    print "Okay"
  else:
    print "Y/N means enter a 'Y' for yes or a 'N' for no."


time = 24.
time_minus_sleep = sleep(time)
time_minus_work = work(time_minus_sleep)
waking_time = time_minus_sleep
percent_free = str(time_minus_work / waking_time * 100)
percent_round = percent_free[:5]

print""
print "You have %.2f hours of freetime." % time_minus_work
waking_time = time_minus_sleep
print "Of the %.0f hours in a day, you are awake for %.2f of them." % (time, waking_time)
There is no need for sleep and work to take the time as an argument. Just return what the user enters and calculate in the main function. The main part of the code should be guarded by a if __name__ == "__main__": guard, which ensures that that code is only executed when running the script but not when importing from it.

Python 2 will soon be no longer supported. If you are starting to learn Python now, learn Python 3 straight away. In the code below the main differences are that raw_input is now input (and the Python 2 input no longer exists), print is no longer a statement, but a function (so surround it with (), instead of ), division is now float division by default (use // for integer division) and finally string formatting has become a lot easier in Python 3.6 with f-strings.

def ask_time(message):
    while True:
        try:
            hours = float(input(message))
            if 0 &lt;= hours &lt;= 24:
                return hours
        except ValueError:
            pass
        print("Please enter a number between 0 and 24")

def see_percent():
    reply = input("Would you like to know the percent of your waking time is free time? (Y/N): ").lower()
    return reply == "y"


if __name__ == "__main__":
    total_time = 24.  # hours
    sleep_time = ask_time("How many hours do you sleep a night?: ")
    work_time = ask_time("How many hours do you work each weekday?: ")

    waking_time = total_time - sleep_time
    free_time = waking_time - work_time
    print(f"You have {free_time:.2f} hours of free time.")
    print(f"Of the 24 hours in a day, you are awake for {waking_time:.2f} of them.")

    if see_percent():
        percent_free = free_time / total_time
        print(f"{percent_free:.2%}.")


I also made a more general ask_time function which ensures that the user enters a valid number between 0 and 24 and keeps on asking if they didn't and used four spaces throughout, as recommended by Python's official style-guide, PEP8.