From f0a6c057910fbe74d6c8158124be2a87d18476ee Mon Sep 17 00:00:00 2001 From: jonnybravo Date: Wed, 27 Mar 2024 13:09:24 +0100 Subject: [PATCH] commit message from python script --- übung/rechner/main.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/übung/rechner/main.py b/übung/rechner/main.py index c24fd1c..2c6492b 100644 --- a/übung/rechner/main.py +++ b/übung/rechner/main.py @@ -1,13 +1,14 @@ #! /usr/bin/env python3 -import random +import random, operator class my_rechner: - def __init__(self, zahl=0): - self.zahl = zahl - self.rechen_art = ['*', '+', '-'] - self.art = random.choice(self.rechen_art) + 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) def check_input(self): @@ -17,21 +18,22 @@ class my_rechner: pass def check_rechnen(self): - self.zahl = random.randint(1, 1000) - self.art = random.choice(self.rechen_art) + 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(self.zahl , self.art) - r = str(str(self.zahl) + ' ' + str(self.art) + ' '+ str(self.zahl)) - summe = eval(r) + print("Rechne {zahl1} {op} {zahl2} ".format(zahl1=self.zahl1, op=self.op, zahl2=self.zahl2)) + summe = self.fn(self.zahl1, self.zahl2) + my_ergebnis = input("Was ist dein Ergebnis :") self.check_rechnen() - print(r) - print(summe) + print("Deine Input", my_ergebnis) + print("Ergebniss", summe) - check_input = input("Noch eine Frage ? :") - if len(check_input) == 1 and check_input == "n": + check_input = input("Willst du aufhöhren ? (j) :") + if len(check_input) == 1 and check_input == "j": break else: print("false")