Commit 4e75114d authored by Linus Jahn's avatar Linus Jahn 🍙

Import stuff

parent 995b6c95
#!/usr/bin/env python3
# -*- coding: cp1252 -*-
"""
Chuck a Luck
"""
from Tkinter import *
from tkMessageBox import *
from random import randint
class Uebung(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=W+E+N+S, padx=5, pady=5)
self.createWidgets()
def createWidgets(self):
self.heading = Label(self, text="Klick den Button!")
self.heading.grid(row=0, column=0, sticky=W+E+N+S, padx=5, pady=5)
self.label = Label(self, text="")
self.label.grid(row=0, column=1, sticky=W+E+N+S, padx=5, pady=5)
Button(self, text="Button", command=self.onClick,
width=30).grid(row=0, column=2, sticky=W+E+N+S, padx=5, pady=10)
def onClick(self):
self.label.config(text="Button gedrueckt.")
root = Tk()
root.wm_title("Uebung")
root.resizable(0,0)
app = Uebung(master=root)
app.mainloop()
GHO Schüler,SCHULE/linus.jahn,f6107,06.09.2018 14:36,file:///C:/Users/linus.jahn/AppData/Roaming/OpenOffice/4;
\ No newline at end of file
from gturtle import *
import math
turtle = makeTurtle()
turtle.hideTurtle()
#turtle.speed(0)
#turtle.back(200)
def drawTree(n = 200):
if n < 2:
return
turtle.forward(n)
turtle.right(45)
drawTree(n * 0.75)
turtle.left(90)
drawTree(n * 0.75)
turtle.right(45)
turtle.back(n)
def drawRectangles(n = 150):
if n <= 1:
return
turtle.left(180)
for i in range(4):
turtle.right(90)
turtle.forward(n)
turtle.back(n)
turtle.left(90)
turtle.left(45)
#turtle.forward(n)
#turtle.back(n)
#turtle.left(180)
drawRectangles(n * 0.99)
def drawRect(n):
repeat 4:
turtle.forward(n)
turtle.left(90)
def drawTriangle(n):
turtle.left(45)
turtle.forward(n * 0.5)
turtle.left(90)
turtle.forward(math.sqrt(n**2 + (n*0.5)**2))
def drawPythagoras(n = 200):
if n <= 2:
return
drawRect(n)
turtle.forward(n)
#drawTriangle(n)
turtle.right(60)
drawPythagoras(math.asin(0.30) * n / math.asin(0.90))
turtle.left(90)
#turtle.towards(100, 0)
#drawTree()
drawPythagoras()
#!/usr/bin/env python2
class MyList():
def __init__(self, list = []):
self.list = list
def __sortAlphabetically(self, list):
if not len(list):
return []
#if list[0]:
def __removeAllFromList(self, element, list):
if not len(list):
return []
if list[0] == element:
return self.__removeAllFromList(element, list[1:])
return list[:1] + self.__removeAllFromList(element, list[1:])
def removeFromList(self, element):
self.list = self.__removeAllFromList(element, self.list)
def __increaseValues(self, value, list):
if not len(list):
return []
return [list[0] + value] + self.__increaseValues(value, list[1:])
def __filterLargerThan(self, value, list):
if not len(list):
return []
if list[0] > value:
return self.__filterLargerThan(value, list[1:])
return [list[0]] + self.__filterLargerThan(value, list[1:])
def __inverseList(self):
if not len(self.list):
return []
return self.__inverseList(self.list[1:]) + self.list[:1]
listA = MyList(["a", "a", "b", "a", "b"])
listA.removeFromList("a")
print(listA.list)
#!/usr/bin/env python2
def numberGuessing(n = 5):
inputN = int(input("Please enter a number: "))
if inputN == n:
print("Number was correct!")
return
if inputN < n:
print("Number is too small.")
else:
print("Number is too large.")
return numberGuessing(n = n)
def summe(n):
if n == 1:
return 1
return n + summe(n - 1)
def fakultaet(n):
if n == 1:
return 1
return n * fakultaet(n - 1)
def pascal(list):
return [list[1] + list[2]] + pascal(list[1:])
def pascal_dreieck(list, row):
print(list)
if (row == 0):
return 0
"""
wip_list = [1]
for i in range(len(list) - 1):
wip_list.append(list[i] + list[i + 1])
wip_list.append(1)
"""
return pascal_dreieck(list, row - 1)
for i in range(5):
list = []
for j in range(7):
list.append(pascal(i, j))
print(list)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python2
import time
from random import randint
import json
import sys
def randList(n):
liste = []
size = 2**32
for i in range(n):
liste.append(randint(0, size))
return liste
def reverseList(n):
liste = []
for i in range(n):
liste = [i] + liste
return liste
reverse = {
"10k": reverseList(10000),
"20k": reverseList(20000),
"50k": reverseList(50000),
# "100k": reverseList(100000)
}
normal = {
"10k": range(10000),
"20k": range(20000),
"50k": range(50000),
# "100k": range(100000)
}
random = {
"10k": randList(10000),
"20k": randList(20000),
"50k": randList(50000),
# "100k": randList(100000)
}
f1 = open("list.reverse.json", "w")
f1.write(json.dumps(reverse, sort_keys=True))
f2 = open("list.normal.json", "w")
f2.write(json.dumps(normal, sort_keys=True))
f3 = open("list.random.json", "w")
f3.write(json.dumps(random, sort_keys=True))
def bubbleSort(liste):
while (True):
swapedItems = False
for i in range(len(liste) - 1):
if (liste[i] > liste[i+1]):
liste[i], liste[i+1] = liste[i+1], liste[i]
# merke dass getauscht werden musste
swapedItems = True
# wenn nicht mehr getausch werden musste, loop beenden
if not swapedItems:
break
unsortiert = [25, 17, 15, 56, 19, 66, 8, 20]
bubbleSort(unsortiert)
print(unsortiert)
"""
def sort(liste):
# counters for stats
start = time.time()
swaped = 0
compared = 0
while (True):
swapedItems = False
for i in range(len(liste) - 1):
if (liste[i] > liste[i+1]):
liste[i], liste[i+1] = liste[i+1], liste[i]
# merke dass getauscht werden musste
swapedItems = True
swaped += 1
compared += 1
# wenn nicht mehr getausch werden musste, loop beenden
if not swapedItems:
break
done = time.time()
timediff = done - start
print("Liste hat {} Elemente, {} mal getauscht und {} mal verglichen (in {})".format(
len(liste), swaped, compared, timediff))
"""
#unsortiert = [25, 17, 15, 56, 19, 66, 8, 20]
#sort(unsortiert)
"""
# Listensortierungsmatrix
for j in range(1000, 2001):
cards = []
for i in range(j):
cards = [i] + cards
sort(cards)
"""
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python2
import json
from time import time
from random import randint
def randList(n):
liste = []
size = 2**32
for i in range(n):
liste.append(randint(0, size))
return liste
def reverseList(n):
liste = []
for i in range(n):
liste = [i] + liste
return liste
def bubbleSort(liste):
while (True):
swapedItems = False
for i in range(len(liste) - 1):
if (liste[i] > liste[i+1]):
liste[i], liste[i+1] = liste[i+1], liste[i]
# merke dass getauscht werden musste
swapedItems = True
# wenn nicht mehr getausch werden musste, loop beenden
if not swapedItems:
break
def miniSort(liste):
for i in range(len(liste) - 1):
first = liste[i];cache = liste[i]
for searcher in range(i + 1, len(liste)):
if liste[searcher] < cache:
cache = liste[searcher]
found = searcher
if cache < first:
liste[i] = cache
liste[found] = first
return liste
def insertSort(n):
for i in range(1, len(n)):
t = n[i]
while i > 0 and t < n[i-1]:
n[i] = n[i-1]
i-=1
n[i] = t
return n
f1 = open("list.reverse.json", "r")
f2 = open("list.normal.json", "r")
f3 = open("list.random.json", "r")
d = json.loads(f1.read())
tDiffs = []
for i in range(10):
l = d["20k"][:]
timeA = time()
insertSort(l)
timeB = time()
timeDiff = timeB - timeA
print(timeDiff)
tDiffs.append(timeDiff)
x = 0.0
for t in tDiffs:
x += t
print("average")
print(x / 10.0)
#!/usr/bin/env python2
import json
from time import time
from random import randint
def randList(n):
liste = []
size = 2**32
for i in range(n):
liste.append(randint(0, size))
return liste
def reverseList(n):
liste = []
for i in range(n):
liste = [i] + liste
return liste
def bubbleSort(liste):
while (True):
swapedItems = False
for i in range(len(liste) - 1):
if (liste[i] > liste[i+1]):
liste[i], liste[i+1] = liste[i+1], liste[i]
# merke dass getauscht werden musste
swapedItems = True
# wenn nicht mehr getausch werden musste, loop beenden
if not swapedItems:
break
def miniSort(liste):
for i in range(len(liste) - 1):
first = liste[i];cache = liste[i]
for searcher in range(i + 1, len(liste)):
if liste[searcher] < cache:
cache = liste[searcher]
found = searcher
if cache < first:
liste[i] = cache
liste[found] = first
return liste
def insertSort(n):
for i in range(1, len(n)):
t = n[i]
while i > 0 and t < n[i-1]:
n[i] = n[i-1]
i-=1
n[i] = t
return n
f1 = open("list.reverse.json", "r")
f2 = open("list.normal.json", "r")
f3 = open("list.random.json", "r")
d = json.loads(f3.read())
l = reverseList(50000)
timeA = time()
bubbleSort(l)
timeB = time()
timeDiff = timeB - timeA
print(timeDiff)
This diff is collapsed.
#!/usr/bin/env python2
import json
from time import time
from random import randint
def randList(n):
liste = []
size = 2**32
for i in range(n):
liste.append(randint(0, size))
return liste
def reverseList(n):
liste = []
for i in range(n):
liste = [i] + liste
return liste
def bubbleSort(liste):
while (True):
swapedItems = False
for i in range(len(liste) - 1):
if (liste[i] > liste[i+1]):
liste[i], liste[i+1] = liste[i+1], liste[i]
# merke dass getauscht werden musste
swapedItems = True
# wenn nicht mehr getausch werden musste, loop beenden
if not swapedItems:
break
def miniSort(liste):
for i in range(len(liste) - 1):
first = liste[i]
cache = liste[i]
for searcher in range(i + 1, len(liste)):
if liste[searcher] < cache:
cache = liste[searcher]
found = searcher
if cache < first:
liste[i] = cache
liste[found] = first
return liste
def insertSort(n):
for i in range(1, len(n)):
t = n[i]
while i > 0 and t < n[i-1]:
n[i] = n[i-1]
i-=1
n[i] = t
return n
f1 = open("list.reverse.json", "r")
f2 = open("list.normal.json", "r")
f3 = open("list.random.json", "r")
d = json.loads(f1.read())
tDiffs = []
for i in range(10):
l = d["20k"][:]
timeA = time()
insertSort(l)
timeB = time()
timeDiff = timeB - timeA
print(timeDiff)
tDiffs.append(timeDiff)
x = 0.0
for t in tDiffs:
x += t
print("average")
print(x / 10.0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment