Python :: Aufgabe #16

10 Lösungen Lösungen öffentlich

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.

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

Lösungen:

1 Kommentar
vote_ok
von FCBFAN2000 (370 Punkte) - 03.12.2014 um 12:21 Uhr
Quellcode ausblenden Python-Code
satz=raw_input("Geben sie einen Satz ein.")
liste=[]
liste.append(satz)
A=satz.lower().count("a")
E=satz.lower().count("e")
I=satz.lower().count("i")
O=satz.lower().count("o")
U=satz.lower().count("u")
print "A : ",A
print "E : ",E
print "I : ",I
print "O : ",O
print "U : ",U
vote_ok
von jigga (4260 Punkte) - 18.05.2015 um 00:16 Uhr
Quellcode ausblenden Python-Code
string = input("Satz eingeben: ")

klein = string.lower()

anzahl = klein.count('a') + klein.count('e') + klein.count('i') + klein.count('o') + klein.count('u')

print()
print("Anzahl der Vokale:",anzahl)
print()
print("A:",klein.count('a'))
print("E:",klein.count('e'))
print("I:",klein.count('i'))
print("O:",klein.count('o'))
print("U:",klein.count('u'))
vote_ok
von devnull (8870 Punkte) - 01.02.2016 um 09:42 Uhr
Quellcode ausblenden Python-Code
#!/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'])
vote_ok
von Nachbar (2820 Punkte) - 10.12.2016 um 11:57 Uhr
Quellcode ausblenden Python-Code
# -*- coding: utf-8 -*-
vokale = "a", "e", "i", "o", "u"
zaehler = 0
satz = "Heute ist ein schoener Tag"

for i in satz:
    if i in vokale:
        zaehler = zaehler + 1
print "Es gibt " + str(zaehler) + " Vokale in diesem Satz.\n"

x = 0
zaehler = 0
while x < 5:
    for i in satz:
        if i == vokale[x]:
            zaehler = zaehler + 1
    print str(vokale[x]) + ": " + str(zaehler)
    zaehler = 0
    x = x + 1
vote_ok
von Y0uLyric (500 Punkte) - 11.12.2016 um 19:24 Uhr
Quellcode ausblenden Python-Code
def eingabe():

    global satz
    satz = input("Geben Sie einen Satz ein: ")

def vokale_zaehlen(satz):
    global anzahl_a
    global anzahl_e
    global anzahl_i
    global anzahl_o
    global anzahl_u
    global vokale
    anzahl_a = 0
    anzahl_e = 0
    anzahl_i = 0
    anzahl_o = 0
    anzahl_u = 0
    vokale = 0

    for x in range(len(satz)):
        if satz[x] == "a" or x == "A":
            anzahl_a += 1
        elif satz[x] == "e" or x == "E":
            anzahl_e += 1
        elif satz[x] == "i" or x == "I":
            anzahl_i += 1
        elif satz[x] == "o" or x == "O":
            anzahl_o += 1
        elif satz[x] == "u" or x == "U":
            anzahl_u += 1
        else:
            None

    vokale = anzahl_a + anzahl_e + anzahl_i + anzahl_o + anzahl_u

def ausgabe(anzahl_a, anzahl_e, anzahl_i, anzahl_o, anzahl_u, vokale):

    print("Vokale: " + str(vokale))
    print("A: " + str(anzahl_a) + "\n E: " + str(anzahl_e) + "\n I: " + str(anzahl_i) + "\n O: " + str(anzahl_o) + "\n U: " + str(anzahl_u))

eingabe()
vokale_zaehlen(satz)
ausgabe(anzahl_a, anzahl_e, anzahl_i, anzahl_o, anzahl_u, vokale)
vote_ok
von troelfzehn (60 Punkte) - 19.10.2018 um 14:40 Uhr
Quellcode ausblenden Python-Code
satz = input("Welcher Satz soll analysiert werden? \n")
a = 0
e = 0
i = 0
o = 0
u = 0

for letter in satz.lower():
    if letter == "a":
        a +=1
    elif letter == "e":
        e +=1
    elif letter == "i":
        i +=1
    elif letter == "o":
        o +=1
    elif letter == "u":
        u +=1

print("Anzahl A:" + str(a))
print("Anzahl E:" + str(e))
print("Anzahl I:" + str(i))
print("Anzahl O:" + str(o))
print("Anzahl U:" + str(u))
vote_ok
von thorbox (200 Punkte) - 22.02.2019 um 15:57 Uhr
Quellcode ausblenden Python-Code
zaehler_a = 0
zaehler_e = 0
zaehler_i = 0
zaehler_o = 0
zaehler_u = 0

satz = input("Geben Sie einen Satz ein:")

for buchstabe in satz:
    if buchstabe == "a" or buchstabe == "A":
        zaehler_a = zaehler_a + 1
    elif buchstabe == "e" or buchstabe == "E":
        zaehler_e = zaehler_e + 1
    elif buchstabe == "i" or buchstabe == "I":
        zaehler_i = zaehler_i + 1
    elif buchstabe == "o" or buchstabe == "O":
        zaehler_o = zaehler_o + 1
    elif buchstabe == "u" or buchstabe == "U":
        zaehler_u = zaehler_u + 1
        
print("Anzahl der Vokale:" + str(zaehler_a + zaehler_e + zaehler_i + zaehler_o + zaehler_u))
print("A:", zaehler_a)
print("E:", zaehler_e)
print("I:", zaehler_i)
print("O:", zaehler_o)
print("U:", zaehler_u)
vote_ok
von torstenkn (150 Punkte) - 01.05.2020 um 14:45 Uhr
Quellcode ausblenden Python-Code
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))

vote_ok
von Sleepyy (320 Punkte) - 27.08.2020 um 12:24 Uhr
Quellcode ausblenden Python-Code
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 27 12:05:20 2020

@author: Robin
"""

inp=0

while not inp:
    try:
        wort = str(input(">>> Bitte ein Wort eingeben: "))
        inp = 1
    except:
        print("")
        print(">>> Bitte nur Buchstaben eingeben !!!")
        
a = wort.count("a")
e = wort.count("e")
i = wort.count("i")
o = wort.count("o")
u = wort.count("u")
zusammen = a+e+i+o+u
print("")
print(">>> Dies ist ein toller Satz.")
print("")
print(">>> Anzahl der Vokale:",zusammen)
print("")
print(">>> A:",a)
print(">>> E:",e)
print(">>> I:",i)
print(">>> O:",o)
print(">>> U:",u)
vote_ok
von PythonLui (400 Punkte) - 08.04.2021 um 14:54 Uhr
Quellcode ausblenden Python-Code
satz = input("Geben Sie einen Satz ein: \n").lower()

vokale = ["a", "e", "i", "o", "u"]
anzahl_vokale = [0, 0, 0, 0, 0]
gesamt = 0

for stelle, vokal in enumerate(vokale):
    anzahl_vokale[stelle] = satz.count(vokal)

for i in range(len(anzahl_vokale)):
    gesamt += anzahl_vokale[i]

print(f"Anzahl der Vokale: {gesamt}")
for i in range(len(vokale)):
    print(f"{vokale[i].upper()}: {anzahl_vokale[i]}")


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
2102615

Du scheinst einen AdBlocker zu nutzen. Ich würde mich freuen, wenn du ihn auf dieser Seite deaktivierst und dich davon überzeugst, dass die Werbung hier nicht störend ist.