Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

# seconds_converter

By: a guest on Mar 1st, 2013  |  syntax: Python  |  size: 1.01 KB  |  views: 36  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
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]))
clone this paste RAW Paste Data
Top