LU06.L05: Längenumrechner

TODO SuMa - Video

converter.py
def main():
    units = ['Meter', 'Zentimeter', 'Meilen', 'Seemeilen']
    factors = [1, 100, 0.000621371, 0.000539957]
 
    print('Einheiten umrechnen')
    for unit in units:
        print(f'* {unit}')
 
    value = float(input('Länge > '))
    unit_from = -1
    while unit_from == -1:
        unit = input('Einheit von >')
        try:
            unit_from = units.index(unit)
        except ValueError:
            print('Ungültige Einheit')
 
    unit_to = -1
    while unit_to == -1:
        unit = input('Einheit nach >')
        try:
            unit_to = units.index(unit)
        except ValueError:
            print('Ungültige Einheit')
 
    result = value * factors[unit_to] / factors[unit_from]
    print(f'{value} {units[unit_from]} = {result} {units[unit_to]}')
    return units, factors

Marcel Suter

  • modul/m319/learningunits/lu06/loesungen/laengen.txt
  • Last modified: 2023/11/13 08:56
  • by 127.0.0.1