Übungsaufgaben

8.6. Übungsaufgaben#

Exercise 8.3 (Praxisaufgabe: Umrechnung kW ↔ PS)

Schreiben Sie ein Python-Programm, das Leistungsangaben umrechnet.

../../_images/k1_abb1.jpg

Abb. 8.3 Foto: Tilman Küpper#

Eingabe:

  • Zahl (Leistung)

  • Umrechnungs-Richtung (1 = kW → PS, 2 = PS → kW)

Hinweis: \(1\,\mathrm{kW} = 1.35962\,\mathrm{PS}\)

Ausgabe: Ergebnis (gerne mit 2 Nachkommastellen)

Optional: Geben Sie bei ungültiger Richtung eine Fehlermeldung aus.

import math

direction = input("Richtung (1 = kW → PS, 2 = PS → kW): ").strip()
---------------------------------------------------------------------------
StdinNotImplementedError                  Traceback (most recent call last)
Cell In[1], line 3
      1 import math
----> 3 direction = input("Richtung (1 = kW → PS, 2 = PS → kW): ").strip()

File /opt/conda/lib/python3.11/site-packages/ipykernel/kernelbase.py:1201, in Kernel.raw_input(self, prompt)
   1199 if not self._allow_stdin:
   1200     msg = "raw_input was called, but this frontend does not support input requests."
-> 1201     raise StdinNotImplementedError(msg)
   1202 return self._input_request(
   1203     str(prompt),
   1204     self._parent_ident["shell"],
   1205     self.get_parent("shell"),
   1206     password=False,
   1207 )

StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.