Hallo zusammen!
Ich habe fast zwei Monate lang nicht programmiert, weil ich keine Zeit hatte. Dementsprechend ist vieles in Vergessenheit geraten, einiges ist kurz davor in Vergessenheit zu geraten 🙂 Um das Gelernte nicht völlig zu verlieren, habe ich schnell einen Rechner skizziert, der von metrischen in nicht-metrische Maße und umgekehrt umrechnet.
Es ist alles ganz einfach – if, elif, print
var = int(input('1: Metric to Imperial\n2: Imperial to Metric\n')) if var == 1: print('Conversion from Metric to Imperial') conversion = int(input('What are we converting: \n 1. Temperature\n 2. Weight\n 3. Length\n 4. Volume\n 5. Speed\n ')) # Temperature conversion if conversion == 1: temperature = int(input(' 1. Celsius -> Fahrenheit\n 2. Celsius -> Kelvin\n')) if temperature == 1: value_temperature = float(input('How many degrees Celsius? :\n')) print(value_temperature, 'degrees Celsius is', round((((9/5) * value_temperature + 32)), 2), 'degrees Fahrenheit') elif temperature == 2: value_temperature = float(input('How many degrees Celsius? :\n')) print(value_temperature, 'degrees Celsius is', round((value_temperature + 273.15), 2), 'Kelvin') # Weight conversion elif conversion == 2: mass = int(input(' 1. Kilograms -> Pounds\n 2. Grams -> Ounces \n')) if mass == 1: value_mass = float(input('How many kilograms? :\n')) print(value_mass, 'kilograms is', round((value_mass * 2.20462), 2), 'pounds') elif mass == 2: value_mass = float(input('How many grams? :\n')) print(value_mass, 'grams is', round((value_mass * 0.035274), 2), 'ounces') # Length conversion elif conversion == 3: length = int(input(' 1. Kilometers -> Miles\n 2. Meters -> Yards\n 3. Meters -> Feet\n 4. Centimeters -> Inches\n 5. Millimeters -> Inches \n')) if length == 1: value_length = float(input('How many kilometers? :\n')) print(value_length, 'kilometers is', round((value_length * 1.60934), 2), 'miles') elif length == 2: value_length = float(input('How many meters? :\n')) print(value_length, 'meters is', round((value_length * 1.09361), 2), 'yards') elif length == 3: value_length = float(input('How many meters? :\n')) print(value_length, 'meters is', round((value_length / 0.3048), 2), 'feet') elif length == 4: value_length = float(input('How many centimeters? :\n')) print(value_length, 'centimeters is', round((value_length * 2.5400013716), 2), 'inches') elif length == 5: value_length = float(input('How many millimeters? :\n')) print(value_length, 'millimeters is', round((value_length / 0.0393701), 2), 'inches') # Volume conversion elif conversion == 4: volume = int(input(' 1. Liters -> Gallons\n 2. Liters -> Pints\n')) if volume == 1: value_volume = float(input('How many liters? : ')) print(value_volume, 'liters is', round((value_volume / 3.785411784), 2), 'gallons') elif volume == 2: value_volume = float(input('How many liters? :\n')) print(value_volume, 'liters is', round((value_volume / 0.56826125), 2), 'pints') # Speed conversion elif conversion == 5: speed = float(input('How many kilometers per hour? : ')) print(speed, 'km/h is', round((speed / 1.60934), 2), 'mph') elif var == 2: print('Conversion from Imperial to Metric') conversion = int(input('What are we converting: \n 1. Temperature\n 2. Weight\n 3. Length\n 4. Volume\n 5. Speed\n ')) # Temperature conversion if conversion == 1: temperature = int(input(' 1. Fahrenheit -> Celsius\n 2. Kelvin -> Celsius\n')) if temperature == 1: value_temperature = float(input('How many degrees Fahrenheit? :\n')) print(value_temperature, 'degrees Fahrenheit =', round(((5/9) * (value_temperature - 32)), 2), 'Celsius') elif temperature == 2: value_temperature = float(input('How many degrees Kelvin? :\n')) print(value_temperature, 'Kelvin =', value_temperature - 273.15, 'Celsius') # Weight conversion if conversion == 2: mass = int(input(' 1. Pounds -> Kilograms\n 2. Ounces -> Grams\n')) if mass == 1: value_mass = float(input('How many pounds? :\n')) print(value_mass, 'pounds is', round((value_mass * 0.453592), 2), 'kilograms') elif mass == 2: value_mass = float(input('How many ounces? :\n')) print(value_mass, 'ounces is', round((value_mass * 28.3), 2), 'grams') # Length conversion if conversion == 3: length = int(input(' 1. Miles -> Kilometers\n 2. Yards -> Meters\n 3. Feet -> Meters\n 4. Inches -> Centimeters\n')) if length == 1: value_length = float(input('How many miles? :\n')) print(value_length, 'miles =', round((value_length / 0.621371), 2), 'kilometers') elif length == 2: value_length = float(input('How many yards? :\n')) print(value_length, 'yards =', round((value_length / 0.9144), 2), 'meters') elif length == 3: value_length = float(input('How many feet? :\n')) print(value_length, 'feet =', round((value_length / 3.28084), 2), 'meters') elif length == 4: value_length = float(input('How many inches? :\n')) print(value_length, 'inches =', round((value_length / 0.393701), 2), 'centimeters') # Volume conversion if conversion == 4: volume = int(input(' 1. Gallons -> Liters\n 2. Pints -> Liters\n')) if volume == 1: value_volume = float(input('How many gallons? : \n')) print(value_volume, 'gallons =', round((value_volume * 3.785411784), 2), 'liters') if volume == 2: value_volume = float(input('How many pints? : \n')) print(value_volume, 'pints =', round((value_volume * 0.473176473), 2), 'liters') # Speed conversion if conversion == 5: speed = float(input('How many miles per hour? :\n')) print(speed, 'mph =', round((speed * 1.60934), 2), 'km/h')
Support the Blog!
Running a blog takes a lot of effort, time, and passion. Your donations help improve the content, inspire new ideas, and keep the project going.
If you’ve enjoyed the blog’s materials, any support would mean the world to me. Thank you for being here! ❤️