Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Cooking Converter Project V1.0
- # <ha>import antigravity http://xkcd.com/353/</ha>
- while True: # clear the screen
- if sys.platform.startswith('win'):
- import os
- os.system('cls')
- break
- elif sys.platform.startswith('linux'):
- import os
- os.system('clear')
- break
- print "What is the amount you are converting from?"
- in_amount = int(raw_input(">"))
- print "\nWhat is the unit you are converting from:"
- print "gram | tbsp | tsp | ml | lt | oz | pnt | cup | qrt | gal? "
- in_unit = raw_input(">")
- print "\nFinally, what is the unit you are converting to:"
- print "gram | tbsp | tsp | ml | lt | oz | pnt | cup | qrt | gal? "
- out_unit = raw_input(">")
- # all related to the gram
- # volmul = volume_unit_multiplier
- def convert(in_amount, in_unit, out_unit):
- volmul = {
- 'gram': 1,
- 'tbsp': 14.8,
- 'tsp' : 4.2,
- 'ml' : 1,
- 'lt' : 1000.,
- 'pnt' : 473.2,
- 'cup' : 236.5,
- 'qrt' : 946.3,
- 'gal' : 3785,
- 'oz' : 28.34
- }
- return in_amount*volmul[in_unit]/volmul[out_unit]
- print "\n%.2f %s\n" % (convert(in_amount, in_unit, out_unit), out_unit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement