Advertisement
Guest User

seconds_converter

a guest
Mar 1st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. minutes_per_hour = 60
  2. hours_per_day = 24
  3. days_per_week = 7
  4. weeks_per_year = 52
  5.  
  6. seconds_per = {'seconds': 1, 'minutes': 60}
  7. seconds_per['hours'] = seconds_per['minutes'] * minutes_per_hour
  8. seconds_per['days'] = seconds_per['hours'] * hours_per_day
  9. seconds_per['weeks'] = seconds_per['days'] * days_per_week
  10. seconds_per['years'] = seconds_per['weeks'] * weeks_per_year
  11.  
  12. print("This program will tell you how many seconds are in a certain number of years, weeks, days, hours, minutes, and seconds.")
  13.  
  14. user_input = {}
  15. units = ['years', 'weeks', 'days', 'hours', 'minutes', 'seconds']
  16. for unit in units:
  17.     user_input[unit] = int(input("Please input the number of {}: ".format(unit)))
  18. print("Computing...")
  19.  
  20. seconds = []
  21. for unit, num in user_input.items():
  22.     seconds.append(num * seconds_per[unit])
  23. seconds = str(sum(seconds))
  24. print("Done!")
  25.  
  26. output = "There are {} seconds in {} years, {} weeks, {} days, {} hours, {} minutes, and {} seconds."
  27. print(output.format(seconds, *[user_input[unit] for unit in units]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement