Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:blc:informatik:glf20:programmieren:listen2 [2020/11/20 08:35] mirco.triner |
lehrkraefte:blc:informatik:glf20:programmieren:listen2 [2020/11/20 08:53] (current) mirco.triner |
||
---|---|---|---|
Line 170: | Line 170: | ||
print(len(liste)) | print(len(liste)) | ||
print(anzahlRichtigerAntworten) | print(anzahlRichtigerAntworten) | ||
- | print(anzahlRichtigerAntworten/ | + | print(anzahlRichtigerAntworten/ |
+ | </ | ||
+ | < | ||
+ | #Aufgabe 2c | ||
+ | #Einfache Rechnungen mit +, -, * & / | ||
+ | #Mögliche Probleme: | ||
+ | #-Benutzer kann bei Divisionen nur eine gewisse Anzahl stellen eingeben | ||
+ | #-einfache Rechnungen bedarfen bei der Multiplikation an kleineren Zahlen | ||
+ | from random import * | ||
+ | |||
+ | liste = [] | ||
+ | |||
+ | while True: | ||
+ | listeElement = [] | ||
+ | funktion = randint(1, | ||
+ | if funktion == 1: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(" | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append(eingabe) | ||
+ | elif funktion == 2: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(" | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append(eingabe) | ||
+ | elif funktion == 3: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(" | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append(eingabe) | ||
+ | else: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | 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, | ||
+ | if resultat == element[3]: | ||
+ | anzahlRichtigerAntworten += 1 | ||
+ | |||
+ | print(len(liste)) | ||
+ | print(anzahlRichtigerAntworten) | ||
+ | print(anzahlRichtigerAntworten/ | ||
+ | </ | ||
+ | < | ||
+ | #Aufgabe 2d | ||
+ | #Einfache Rechnungen mit +, -, * & / inkl. Start und Endzeit | ||
+ | |||
+ | from random import * | ||
+ | import time | ||
+ | from datetime import datetime | ||
+ | |||
+ | liste = [] | ||
+ | start = datetime.now() | ||
+ | |||
+ | while True: | ||
+ | listeElement = [] | ||
+ | funktion = randint(1, | ||
+ | if funktion == 1: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(" | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append(eingabe) | ||
+ | elif funktion == 2: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(" | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append(eingabe) | ||
+ | elif funktion == 3: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(" | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append(eingabe) | ||
+ | else: | ||
+ | zahl1 = randint(1, | ||
+ | zahl2 = randint(1, | ||
+ | eingabe = input(" | ||
+ | if eingabe == ' | ||
+ | break | ||
+ | else: | ||
+ | listeElement.append(zahl2) | ||
+ | listeElement.append("/" | ||
+ | listeElement.append(zahl1) | ||
+ | listeElement.append(eingabe) | ||
+ | liste.append(listeElement) | ||
+ | |||
+ | end = datetime.now() | ||
+ | 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, | ||
+ | if resultat == element[3]: | ||
+ | anzahlRichtigerAntworten += 1 | ||
+ | |||
+ | print(len(liste)) | ||
+ | print(anzahlRichtigerAntworten) | ||
+ | print(anzahlRichtigerAntworten/ | ||
+ | print(end - start) | ||
</ | </ | ||