lehrkraefte:blc:informatik:glf20:programmieren:listen2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lehrkraefte:blc:informatik:glf20:programmieren:listen2 [2020/11/20 08:49]
mirco.triner
lehrkraefte:blc:informatik:glf20:programmieren:listen2 [2020/11/20 08:53] (current)
mirco.triner
Line 181: Line 181:
  
 liste = [] liste = []
 +
 +while True:
 +    listeElement = []
 +    funktion = randint(1,4)
 +    if funktion == 1:
 +        zahl1 = randint(1,100)
 +        zahl2 = randint(1,100)
 +        eingabe = input("%d + %d"% (zahl1, zahl2))
 +        if eingabe == 'q':
 +            break
 +        else:
 +            listeElement.append(zahl1)
 +            listeElement.append("+")
 +            listeElement.append(zahl2)
 +            listeElement.append(eingabe)
 +    elif funktion == 2:
 +        zahl1 = randint(1,100)
 +        zahl2 = randint(1,100)
 +        eingabe = input("%d - %d"% (zahl1, zahl2))
 +        if eingabe == 'q':
 +            break
 +        else:
 +            listeElement.append(zahl1)
 +            listeElement.append("-")
 +            listeElement.append(zahl2)
 +            listeElement.append(eingabe)
 +    elif funktion == 3:
 +        zahl1 = randint(1,10)
 +        zahl2 = randint(1,10)
 +        eingabe = input("%d * %d"% (zahl1, zahl2))
 +        if eingabe == 'q':
 +            break
 +        else:
 +            listeElement.append(zahl1)
 +            listeElement.append("*")
 +            listeElement.append(zahl2)
 +            listeElement.append(eingabe)
 +    else:
 +        zahl1 = randint(1,10)
 +        zahl2 = randint(1,10)
 +        eingabe = input("%d / %d"% (zahl1, zahl2))
 +        if eingabe == 'q':
 +            break
 +        else:
 +            listeElement.append(zahl1)
 +            listeElement.append("/")
 +            listeElement.append(zahl2)
 +            listeElement.append(eingabe)
 +    liste.append(listeElement)
 +    
 +
 +anzahlRichtigerAntworten = 0
 +
 +for element in liste:
 +    if element[1] == "+":
 +        resultat = element[0] + element[2]
 +        if resultat == element[3]:
 +            anzahlRichtigerAntworten += 1
 +    elif element[1] == "-":
 +        resultat = element[0] - element[2]
 +        if resultat == element[3]:
 +            anzahlRichtigerAntworten += 1
 +    elif element[1] == "*":
 +        resultat = element[0] * element[2]
 +        if resultat == element[3]:
 +            anzahlRichtigerAntworten += 1
 +    else:
 +        resultat = element[0] / element[2]
 +        resultat = round(resultat,2)
 +        if resultat == element[3]:
 +            anzahlRichtigerAntworten += 1
 +            
 +print(len(liste))
 +print(anzahlRichtigerAntworten)
 +print(anzahlRichtigerAntworten/len(liste)*100)
 +</code>
 +<code>
 +#Aufgabe 2d
 +#Einfache Rechnungen mit +, -, * & / inkl. Start und Endzeit
 +
 +from random import *
 +import time
 +from datetime import datetime
 +
 +liste = []
 +start = datetime.now()
  
 while True: while True:
Line 231: Line 317:
     liste.append(listeElement)     liste.append(listeElement)
          
 +end = datetime.now()
 anzahlRichtigerAntworten = 0 anzahlRichtigerAntworten = 0
  
Line 256: Line 342:
 print(anzahlRichtigerAntworten) print(anzahlRichtigerAntworten)
 print(anzahlRichtigerAntworten/len(liste)*100) print(anzahlRichtigerAntworten/len(liste)*100)
 +print(end - start)
 </code> </code>
  
  • lehrkraefte/blc/informatik/glf20/programmieren/listen2.1605858574.txt.gz
  • Last modified: 2020/11/20 08:49
  • by mirco.triner