Python :: Aufgabe #16 :: Lösung #3
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
#3

von devnull (8870 Punkte)
- 01.02.2016 um 09:42 Uhr

#!/usr/bin/python3 chard = {} # empty dictionary text = input("Satz: ") for c in ('a','e','i','o','u'): chard[c] = 0; for c in text.lower(): if c in ('a','e','i','o','u'): chard[c] += 1; print("Anzahl Vokale:", chard['a']+chard['e']+chard['i']+chard['o']+chard['u']) print("A:", chard['a']) print("E:", chard['e']) print("I:", chard['i']) print("O:", chard['o']) print("U:", chard['u'])
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1