ha4 hinzugefügt
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
words = ["Apfel", "Banane", "Kirsche", "Kiwi", "Melone"]
|
||||
pri=sum(len(word) for word in words if word.startswith("K"))
|
||||
print(pri)
|
||||
@@ -0,0 +1,58 @@
|
||||
import pygame
|
||||
from game import Game
|
||||
|
||||
class DrawGame(Game):
|
||||
def __init__(self):
|
||||
super().__init__("Zeichenprogramm", fps=60, size=(800, 600))
|
||||
self.state = []
|
||||
self.history = []
|
||||
self.drawing = False
|
||||
self.current_stroke = []
|
||||
|
||||
def handle_event(self, event):
|
||||
if event.type == pygame.QUIT:
|
||||
return False
|
||||
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||
self.drawing = True
|
||||
self.current_stroke = [event.pos]
|
||||
|
||||
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
|
||||
if self.drawing and len(self.current_stroke) > 1:
|
||||
self.push_history()
|
||||
new_state = [stroke[:] for stroke in self.state]
|
||||
new_state.append(self.current_stroke[:])
|
||||
self.state = new_state
|
||||
self.drawing = False
|
||||
self.current_stroke = []
|
||||
|
||||
elif event.type == pygame.MOUSEMOTION and self.drawing:
|
||||
self.current_stroke.append(event.pos)
|
||||
|
||||
elif event.type == pygame.KEYDOWN and event.key == pygame.K_BACKSPACE:
|
||||
if self.history:
|
||||
self.state = self.history.pop()
|
||||
|
||||
return True
|
||||
|
||||
def push_history(self):
|
||||
snapshot = [stroke[:] for stroke in self.state]
|
||||
self.history.append(snapshot)
|
||||
if len(self.history) > 5:
|
||||
self.history.pop(0)
|
||||
|
||||
def draw_game(self):
|
||||
self.screen.fill((255, 255, 255))
|
||||
|
||||
for stroke in self.state:
|
||||
if len(stroke) > 1:
|
||||
pygame.draw.lines(self.screen, (0, 0, 0), False, stroke, 2)
|
||||
|
||||
if self.drawing and len(self.current_stroke) > 1:
|
||||
pygame.draw.lines(self.screen, (0, 0, 0), False, self.current_stroke, 2)
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
DrawGame().run()
|
||||
@@ -0,0 +1,6 @@
|
||||
t = (1, 2, 3)
|
||||
|
||||
print(t)
|
||||
print(*t)
|
||||
print(t, 4)
|
||||
print(*t, 4)
|
||||
@@ -0,0 +1,24 @@
|
||||
from time import perf_counter as pfc
|
||||
from functools import wraps
|
||||
|
||||
def timing(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
start = pfc()
|
||||
result = func(*args, **kwargs)
|
||||
end = pfc()
|
||||
print(f"Dauer: {end - start:.4f}s")
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
|
||||
@timing
|
||||
def meine_funktion(n):
|
||||
total = 0
|
||||
for i in range(n):
|
||||
total += i
|
||||
return total
|
||||
|
||||
|
||||
ergebnis = meine_funktion(1000000)
|
||||
print("Ergebnis:", ergebnis)
|
||||
Reference in New Issue
Block a user