Advertisement
The_KGB

[Python] Random Unit Converter....Not advanced

Apr 2nd, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  1. #Basic unit converter in python
  2. #run select()
  3. #I'll add more when I care. Just a basic converter. Do what you want with it.
  4.  
  5.  
  6. #Conversion Selector
  7. def Convert():
  8.     print 'Conversion Menu :D';
  9.     print '+--------------------------------------+';
  10.     print '[1] Convert Fahrenheit to Celsius';
  11.     print '[2] Convert Celsius to Fahrenheit';
  12.     print '[3] Convert Inches to Centimenters';
  13.     print '[4] Convert Centimeters to Inches';
  14.     print '[5] Convert Gallons to Liters';
  15.     print '[6] Convert Liters to Gallons';
  16.     print '[7] Convert Yards to Meters';
  17.     print '[8] Convert Meters to Yards';
  18.     print '[9] Convert Pounds to Kilograms';
  19.     print '[10] Convert Kilograms to Pounds';
  20.     print '+--------------------------------------+';
  21.     print 'Enjoy! -The_KGB';
  22.     print 'Be sure to customize this, make it more accurate or whatever it is that you do :D';
  23.     print ' ';
  24.  
  25. def select():
  26.     Convert();
  27.     choice = input('Enter the conversion desired: ')
  28.     if (choice == 1):
  29.         F2C();
  30.     elif (choice == 2):
  31.         C2F();
  32.     elif (choice == 3):
  33.         I2C();
  34.     elif (choice == 4):
  35.         C2I();
  36.     elif (choice == 5):
  37.         G2L();
  38.     elif (choice == 6):
  39.         L2G();
  40.     elif (choice == 7):
  41.         Y2M();
  42.     elif (choice == 8):
  43.         M2Y();
  44.     elif (choice == 9):
  45.         P2K();
  46.     elif (choice == 10):
  47.         K2P();
  48.     else:
  49.         print 'Invalid choice: ', choice;
  50.  
  51. #Fahrenheit to Celsius
  52. def F2C():
  53.     fahrenheit = input('Enter degrees in Fahrenheit: ');
  54.     celsius = (5.0/9.0) * (fahrenheit - 32);
  55.     print fahrenheit, 'Fahrenheit =',celsius, 'Celsius';
  56.  
  57. #Celsius to Fahrenheit
  58. def C2F():
  59.     celsius = input('Enter degrees in Celsius: ');
  60.     fahrenheit = (9.0 / 5.0) * celsius +32;
  61.     print celsius, 'Celsius =', fahrenheit, 'fahrenheit';
  62.  
  63. # Inches to Centimeters
  64. def I2C():
  65.     inches = input('Enter length in inches: ');
  66.     centimeters = inches*2.54;
  67.     print inches, 'Inches =', centimeters, 'Centimeters';
  68.  
  69. # Centimeters to inches
  70. def C2I():
  71.     centimeters = input('Enter length in Centimeters: ');
  72.     inches = centimeters/2.54;
  73.     print centimeters, 'Centimeters =', inches, 'Inches';
  74.  
  75. #Gallons to Liters
  76. def G2L():
  77.     gallons = input('Enter volume in Gallons: ');
  78.     liters = gallons*3.7854118;
  79.     print gallons, 'Gallons =', liters, 'Liters';
  80.  
  81. #Liters to Gallons
  82. def L2G():
  83.     liters = input('Enter volume in Liters: ');
  84.     gallons = liters/3.7854118;
  85.     print liters, 'Liters =', gallons, 'Gallons';
  86.  
  87. #Yards to Meters
  88. def Y2M():
  89.     yards = input('Enter length in Yards: ');
  90.     meters = yards*.9144;
  91.     print yards, 'Yards =', meters, 'Meters';
  92.  
  93. #Meters to Yards
  94. def M2Y():
  95.     meters = input('Enter length in Meters: ');
  96.     yards = meters/.9144;
  97.     print meters, 'Meters =', yards,'Yards';
  98.  
  99. #Pounds to Kilograms
  100. def P2K():
  101.     pounds = input('Enter mass in Pounds: ');
  102.     kilograms = pounds/.4536;
  103.     print pounds, 'Pounds =', kilograms, 'Kilograms';
  104.  
  105. #Kilograms to Pounds
  106. def K2P():
  107.     kilograms = input('Enter mass in Kilograms: ');
  108.     pounds = kilograms*.4536;
  109.     print kilograms, 'Kilograms =', pounds, 'Pounds';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement