Gå til innhold

Hjelp med python skoleoppgave


Anbefalte innlegg

Videoannonse
Annonse

Dette kan løses f.eks ved at man går igjennom hver bokstav i listen, og ser om det er en stor eller liten H. Hvis det er det, øker man en teller med en. Hvis det er en stor eller liten B øker man en annen teller, og en siste teller hvis det er stor eller liten U.

Noen nyttige kilder:

Python Functions (w3schools.com)

Python For Loops (w3schools.com)

Python Conditions (w3schools.com)

Python Lists (w3schools.com)

Takk for svarene det ser litt bedre ut enn det jeg har rablet sammen.

Sitat

matches = input("skriv in resultater:")
home_draw_away = matches


#Teller h og H
count1 = sum(map(lambda x: 1 if 'h' in x else 0, matches))
count2 = sum(map(lambda x: 1 if 'H' in x else 0, matches))
counth = count1 + count2

#Teller u og U
count3 = sum(map(lambda x: 1 if 'u' in x else 0, matches))
count4 = sum(map(lambda x: 1 if 'U' in x else 0, matches))
countu = count3 + count4

#Teller b og B
count5 = sum(map(lambda x: 1 if 'b' in x else 0, matches))
count6 = sum(map(lambda x: 1 if 'B' in x else 0, matches))
countb = count5 + count6

# Utskrift
print (counth, countu, countb)

 

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...