Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Basic unit converter in python
- #run select()
- #I'll add more when I care. Just a basic converter. Do what you want with it.
- #Conversion Selector
- def Convert():
- print 'Conversion Menu :D';
- print '+--------------------------------------+';
- print '[1] Convert Fahrenheit to Celsius';
- print '[2] Convert Celsius to Fahrenheit';
- print '[3] Convert Inches to Centimenters';
- print '[4] Convert Centimeters to Inches';
- print '[5] Convert Gallons to Liters';
- print '[6] Convert Liters to Gallons';
- print '[7] Convert Yards to Meters';
- print '[8] Convert Meters to Yards';
- print '[9] Convert Pounds to Kilograms';
- print '[10] Convert Kilograms to Pounds';
- print '+--------------------------------------+';
- print 'Enjoy! -The_KGB';
- print 'Be sure to customize this, make it more accurate or whatever it is that you do :D';
- print ' ';
- def select():
- Convert();
- choice = input('Enter the conversion desired: ')
- if (choice == 1):
- F2C();
- elif (choice == 2):
- C2F();
- elif (choice == 3):
- I2C();
- elif (choice == 4):
- C2I();
- elif (choice == 5):
- G2L();
- elif (choice == 6):
- L2G();
- elif (choice == 7):
- Y2M();
- elif (choice == 8):
- M2Y();
- elif (choice == 9):
- P2K();
- elif (choice == 10):
- K2P();
- else:
- print 'Invalid choice: ', choice;
- #Fahrenheit to Celsius
- def F2C():
- fahrenheit = input('Enter degrees in Fahrenheit: ');
- celsius = (5.0/9.0) * (fahrenheit - 32);
- print fahrenheit, 'Fahrenheit =',celsius, 'Celsius';
- #Celsius to Fahrenheit
- def C2F():
- celsius = input('Enter degrees in Celsius: ');
- fahrenheit = (9.0 / 5.0) * celsius +32;
- print celsius, 'Celsius =', fahrenheit, 'fahrenheit';
- # Inches to Centimeters
- def I2C():
- inches = input('Enter length in inches: ');
- centimeters = inches*2.54;
- print inches, 'Inches =', centimeters, 'Centimeters';
- # Centimeters to inches
- def C2I():
- centimeters = input('Enter length in Centimeters: ');
- inches = centimeters/2.54;
- print centimeters, 'Centimeters =', inches, 'Inches';
- #Gallons to Liters
- def G2L():
- gallons = input('Enter volume in Gallons: ');
- liters = gallons*3.7854118;
- print gallons, 'Gallons =', liters, 'Liters';
- #Liters to Gallons
- def L2G():
- liters = input('Enter volume in Liters: ');
- gallons = liters/3.7854118;
- print liters, 'Liters =', gallons, 'Gallons';
- #Yards to Meters
- def Y2M():
- yards = input('Enter length in Yards: ');
- meters = yards*.9144;
- print yards, 'Yards =', meters, 'Meters';
- #Meters to Yards
- def M2Y():
- meters = input('Enter length in Meters: ');
- yards = meters/.9144;
- print meters, 'Meters =', yards,'Yards';
- #Pounds to Kilograms
- def P2K():
- pounds = input('Enter mass in Pounds: ');
- kilograms = pounds/.4536;
- print pounds, 'Pounds =', kilograms, 'Kilograms';
- #Kilograms to Pounds
- def K2P():
- kilograms = input('Enter mass in Kilograms: ');
- pounds = kilograms*.4536;
- print kilograms, 'Kilograms =', pounds, 'Pounds';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement