Added user input, and checking if word is present in the dict to show a translation
This commit is contained in:
19
Kapitel 6/6-2_daten_aus_einer_datei_lesen.py
Normal file → Executable file
19
Kapitel 6/6-2_daten_aus_einer_datei_lesen.py
Normal file → Executable file
@@ -14,4 +14,21 @@ for line in fobj:
|
||||
woerter[zuordnung[0]] = zuordnung[1]
|
||||
|
||||
#sobald alle werte im Dictionary woerter abgelegt sind, Datei schließen
|
||||
fobj.close()
|
||||
fobj.close()
|
||||
|
||||
# unendliche Schleife zur Abfrage der Übersetzung
|
||||
while True:
|
||||
# Abfragen des Wortes zum Übersetzen
|
||||
wort = input("Geben Sie ein Wort ein: ")
|
||||
|
||||
# prüfen ob das Wort im Dictionary vorkommt
|
||||
if wort in woerter:
|
||||
|
||||
#Ausgabe der Übersetzung, Wort vorhanden
|
||||
print("Das deutsche Wort lautet:", woerter[wort])
|
||||
|
||||
# Wort nicht im Dictionary
|
||||
else:
|
||||
|
||||
#Ausgabe Fehlermeldung, Wort nicht vorhanden
|
||||
print("Das Wort ist unbekannt")
|
||||
|
||||
Reference in New Issue
Block a user