Advertisement
Guest User

temperature

a guest
Jul 1st, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. #Khofo temp converter
  2. # -*- coding: utf-8 -*-
  3.  
  4.  
  5. #Functions
  6.  
  7.                
  8. def convert():
  9.     print "Welcome tp khofo's temperature converter"
  10.     while True:
  11.          
  12.         try:
  13.             temp = int(raw_input("Please choose 1. Celsius to Fahrenheit, or 2. Fahrenheit to Celsius: "))
  14.             if temp == 1:
  15.                 cel = float(raw_input("Please enter the temperature in Celsius u wish to convert: "))
  16.                 break
  17.             elif temp == 2:
  18.                 fah = float(raw_input("Please enter the temperature in Fahrenheit u wish to convert: "))
  19.                 break
  20.                    
  21.             else:
  22.                 print "Error: Please retry"
  23.                      
  24.         except:
  25.                  
  26.             print "Error: Please retry"
  27.    
  28.    
  29.     if temp == 1:
  30.        
  31.         converted_fah = (cel*float(9/5))+32
  32.         print ("%d C In fahrenheit is: %d F") % (cel, converted_fah)
  33.    
  34.     elif temp == 2:
  35.         converted_cel = float(fah-32)*float(5/9)
  36.         print ("%d F in Celsius is: %d C") % (fah, converted_cel)
  37.  
  38. def _end_():
  39.    
  40.     print "Thank you for"
  41.     retry = raw_input("To restart type 'restart' to exit press anything: ")
  42.     if retry == "restart":
  43.         convert()
  44.     else:
  45.         print "Bye"
  46.        
  47. def main():
  48.     convert()
  49.     _end_()
  50.  
  51. #End of Functions
  52.  
  53. #######################################    
  54.  
  55. print main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement