Files

44 lines
1.4 KiB
Python

#! /usr/bin/env python3
import random, operator
class my_rechner:
def __init__(self):
self.zahl1 = random.randint(1, 1000)
self.zahl2 = random.randint(1, 1000)
self.operators = [('+', operator.add), ('-', operator.sub), ('*', operator.mul), ('/', operator.truediv) ]
self.op, self.fn = random.choice(self.operators)
self.count_true = 0
self.count_false = 0
def check_rechnen(self):
self.zahl1 = random.randint(1, 1000)
self.zahl2 = random.randint(1, 1000)
self.op, self.fn = random.choice(self.operators)
def main_run(self):
while True:
print("Rechne {zahl1} {op} {zahl2} ".format(zahl1=self.zahl1, op=self.op, zahl2=self.zahl2))
summe = round(float(self.fn(self.zahl1, self.zahl2)),2)
my_ergebnis = float(input("Was ist dein Ergebnis :"))
self.check_rechnen()
print("Deine Input", my_ergebnis)
if my_ergebnis == summe:
self.count_true = self.count_true + 1
print("richtig !!!")
print("Ergebniss", summe)
print("Du hast insgesamt", self.count_true, "richtig")
check_input = input("Willst du aufhöhren ? (j) :")
if len(check_input) == 1 and check_input == "j":
break
if __name__ == "__main__":
print("Running Main", "." * 3)
rechnen_now = my_rechner()
rechnen_now.main_run()