I started coding about a week ago and want feedback on a free time calculator project. I’m not trying to create anything fancy that I’ll actually use; rather, I’m trying to learn to write code effectively.
I’m looking for feedback on the way I organized my code. Is there a more effective way to have written this code? Thanks!
#this program will calulate the user's free time. #The user will be able to chose whether it also #calculates free time percentage based on waking time. 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)