summaryrefslogtreecommitdiff
path: root/zahlenspiel.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-11-23 12:18:04 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2014-11-23 12:18:04 +0100
commit5d3189d7345dd3b26a5753a16020ed4f7df0c4b1 (patch)
tree8b260aa3116d6a2cdf58950e332726a3678754d3 /zahlenspiel.py
parentc8aa48924b284512075432b042ca15c31394ed14 (diff)
downloadbwinf-33-5d3189d7345dd3b26a5753a16020ed4f7df0c4b1.tar.gz
bwinf-33-5d3189d7345dd3b26a5753a16020ed4f7df0c4b1.zip
Verschieben aller Dateien in Unterordner
Diffstat (limited to 'zahlenspiel.py')
-rwxr-xr-xzahlenspiel.py52
1 files changed, 0 insertions, 52 deletions
diff --git a/zahlenspiel.py b/zahlenspiel.py
deleted file mode 100755
index e8891f9..0000000
--- a/zahlenspiel.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-# getestet mit Python 2.7.8 und 3.4.2
-'''Berechnet einen Bruch zur Übung des Kürzens'''
-
-from random import randrange
-
-def gcd(vala, valb):
- '''Berechnet den größten gemeinsamen Teiler nach Euklid'''
- while valb:
- vala, valb = valb, vala % valb
- return vala
-
-def bruch(stufe):
- '''Berechnet einen ungekürzten Bruch vala/valb
-mit gekürztem Bruch valp/valq nach Schwierigkeits`stufe`.
-`stufe` ist 0 (leicht), 1 (mittel) oder 2 (schwer)'''
-
- length = 4 if stufe == 0 else 5
-
- erfolg = False
- while not erfolg:
- suchen = True
- while suchen:
- valp = randrange(1, (stufe + 1) * 10)
- valq = randrange(stufe * 10 - valp, (stufe + 1) * 10 - valp)
- suchen = (gcd(valp, valq) != 1) # falls nicht kürzbar
-
- valx = 2
- suchen = True
- while suchen:
- vala, valb = valp * valx, valq * valx
-
- if len(str(vala)) + len(str(valb)) == length:
- suchen = False
- erfolg = True
- else:
- valx += 1
- if len(str(vala)) + len(str(valb)) > length:
- suchen = erfolg = False # neue Zahlen generieren
-
- return vala, valb, valp, valq
-
-def aufgaben(stufe, anzahl):
- '''gibt `anzahl` Aufgaben mit `stufe` (0 - leicht, 2 - schwer) aus'''
- for _ in range(anzahl):
- vala, valb, valp, valq = bruch(stufe)
- print(str(vala) + " / " + str(valb) + \
- " = " + str(valp) + " / " + str(valq))
-
-if __name__ == "__main__":
- aufgaben(randrange(4), randrange(1, 10))