import random import time d={} def aufgabe(a, b, operator): if operator == 1: print(a, "+", b) elif operator == 2: print(a, "*", b) elif operator == 3: print(a, "-", b) def pruefen(eingabe): if int(eingabe) != c: print(str(eingabe) + " ist falsch.") else: print(str(eingabe) + " ist richtig.") print("Wie lautet Ihr Name?") name=input() d['Name']=name print("Hallo, "+ name + "! Hier ist Deine Aufgabe:") anfang=time.time() zahl1=random.randint(1,100) zahl2=random.randint(1,100) zahl3=random.randint(1,3) aufgabe(zahl1, zahl2, zahl3) if zahl3 == 1: d['Aufgabe']= str(zahl1)+ " + "+ str(zahl2) elif zahl3 == 2: d['Aufgabe']= str(zahl1)+ " * "+ str(zahl2) elif zahl3 == 3: d['Aufgabe']= str(zahl1)+ " - "+ str(zahl2) if zahl3 == 1: c = zahl1 + zahl2 elif zahl3 == 2: c = zahl1 * zahl2 elif zahl3 == 3: c = zahl1 - zahl2 v=1 loesung=int(input("Bitte gib das Ergebnis ein: ")) d['Rateversuche']=[loesung] pruefen(loesung) while loesung !=c: v=v+1 loesung=int(input("Bitte gib das Ergebnis ein: ")) d['Rateversuche'].append(loesung) pruefen(loesung) ende=time.time() zeit=int(ende)-int(anfang) d['Dauer']=zeit print("Du hast", v, "Versuch(e) und", zeit, "Sekunden gebraucht.") import pprint pprint.pprint(d)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question