funcs
This commit is contained in:
commit
2ac32bc21f
18 files changed
+365
No files matched your search
@@ -0,0 +1,7 @@
|
||||
numbers = [1, 2, 3, 4, 5]
|
||||
|
||||
#doubled = list(map(lambda x: x * 2, numbers))
|
||||
#print(doubled)
|
||||
|
||||
def double(numbers):
|
||||
return list(map(lambda x: x * 2, numbers))
|
||||
@@ -0,0 +1,8 @@
|
||||
words = ["Hofmann", "was", "right", "about", "something"]
|
||||
|
||||
#upper_words = list(map(lambda w: w.upper(), words))
|
||||
#sentence = " ".join(upper_words)
|
||||
#print(sentence)
|
||||
|
||||
def trump(words):
|
||||
return " ".join(map(lambda w: w.upper(), words))
|
||||
@@ -0,0 +1,7 @@
|
||||
numbers = list(range(1, 21))
|
||||
|
||||
#even = list(filter(lambda x: x % 2 == 0, numbers))
|
||||
#print(even)
|
||||
|
||||
def even(numbers):
|
||||
return list(filter(lambda x: x % 2 == 0, numbers))
|
||||
Whitespace-only changes.
@@ -0,0 +1,9 @@
|
||||
from functools import reduce
|
||||
|
||||
numbers = [1, 2, 3, 4, 5]
|
||||
|
||||
#product = reduce(lambda a, b: a * b, numbers)
|
||||
#print(product)
|
||||
|
||||
def product(numbers):
|
||||
return reduce(lambda a, b: a * b, numbers)
|
||||
Whitespace-only changes.
@@ -0,0 +1,38 @@
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
class Game:
|
||||
"""Basic Pygame game loop.
|
||||
|
||||
Subclasses **must** implement:
|
||||
* ``update_game`` – update state, return ``False`` to quit.
|
||||
* ``draw_game`` – render to the screen.
|
||||
"""
|
||||
|
||||
def __init__(self, title: str, fps: int, size: tuple[int, int]):
|
||||
pygame.init()
|
||||
self.screen = pygame.display.set_mode(size)
|
||||
pygame.display.set_caption(title)
|
||||
self.clock = pygame.time.Clock()
|
||||
self.fps = fps
|
||||
self.size = size
|
||||
|
||||
def run(self) -> None:
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if running:
|
||||
running = self.update_game()
|
||||
self.draw_game()
|
||||
pygame.display.flip()
|
||||
self.clock.tick(self.fps)
|
||||
pygame.quit()
|
||||
|
||||
def update_game(self) -> bool:
|
||||
raise NotImplementedError
|
||||
|
||||
def draw_game(self) -> None:
|
||||
raise NotImplementedError
|
||||
Whitespace-only changes.
Reference in new issue
Block a user