Python :: Aufgabe #16 :: Lösung #8
10 Lösungen

#16
Vokale zählen in einem beliebigen Satz
Anfänger - Python
von Dome
- 28.12.2012 um 23:58 Uhr
Programmieren Sie ein Programm, welches die Anzahl aller Vokale in einem zuvor eingegebenen Satz ausgibt.
Optional wäre die Ausgabe wie oft welcher Vokal in dem Satz vorhanden ist.
Optional wäre die Ausgabe wie oft welcher Vokal in dem Satz vorhanden ist.
Konsolenausgabe:
Geben Sie einen Satz ein :
Dies ist ein toller Satz.
Anzahl der Vokale : 8
A: 1
E: 3
I: 3
O: 1
U: 0
#8

von torstenkn (150 Punkte)
- 01.05.2020 um 14:45 Uhr

vocalDict = {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0, "Vokale gesamt": 0} mySentence = input('Geben Sie einen Satz ein: ') for char in mySentence: if char == "a" or char == "A": vocalDict["a"] = vocalDict["a"] + 1 vocalDict["Vokale gesamt"] = vocalDict["Vokale gesamt"] + 1 elif char == "e" or char == "E": vocalDict["e"] = vocalDict["e"] + 1 vocalDict["Vokale gesamt"] = vocalDict["Vokale gesamt"] + 1 elif char == "i" or char == "I": vocalDict["i"] = vocalDict["i"] + 1 vocalDict["Vokale gesamt"] = vocalDict["Vokale gesamt"] + 1 elif char == "o" or char == "O": vocalDict["o"] = vocalDict["o"] + 1 vocalDict["Vokale gesamt"] = vocalDict["Vokale gesamt"] + 1 elif char == "u" or char == "U": vocalDict["u"] = vocalDict["u"] + 1 vocalDict["Vokale gesamt"] = vocalDict["Vokale gesamt"] + 1 for key, vocals in vocalDict.items(): print(key + ": " + str(vocals))
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1