#Anything I find interesting/do not know remains here fruits = ["apple", "banana", "cherry"] x, y, z = fruits print(x) print(y) print(z) x = 1 # int y = 2.8 # float z = 1j # complex #convert from int to float: a = float(x) #convert from float to int: b = int(y) #convert from int to complex: c = complex(x) print(a) print(b) print(c) print(type(a)) print(type(b)) print(type(c)) a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.""" print(a) #in the result, the line breaks are inserted at the same position as in the code. a = "Hello, World!" print(a[1]) a = "Hello, World!" print(len(a)) txt = "The best things in life are free!" print("free" in txt) b = "Hello, World!" print(b[2:5]) b = "Hello, World!" print(b[-5:-2]) a = "Hello, World!" print(a.replace("H", "J")) age = 36 txt = "My name is John, and I am {}" print(txt.format(age)) class myclass(): def __len__(self): return 0 myobj = myclass() print(bool(myobj)) thislist = ["apple", "banana", "cherry"] print(len(thislist)) thislist = ["apple", "banana", "cherry"] thislist.insert(2, "watermelon") print(thislist) thislist = ["apple", "banana", "cherry"] tropical = ["mango", "pineapple", "papaya"] thislist.extend(tropical) print(thislist) thislist = ["apple", "banana", "cherry"] thistuple = ("kiwi", "orange") thislist.extend(thistuple) print(thislist) thislist = ["apple", "banana", "cherry"] thislist.clear() print(thislist) thislist = ["apple", "banana", "cherry"] for x in thislist: print(x) thislist = ["apple", "banana", "cherry"] for i in range(len(thislist)): print(thislist[i]) fruits = ["apple", "banana", "cherry", "kiwi", "mango"] newlist = [x for x in fruits if "a" in x] print(newlist) thislist = ["orange", "mango", "kiwi", "pineapple", "banana"] thislist.sort(reverse = True) print(thislist) def myfunc(n): return abs(n - 50) thislist = [100, 50, 65, 82, 23] thislist.sort(key = myfunc) print(thislist) thislist = ["banana", "Orange", "Kiwi", "cherry"] thislist.sort(key = str.lower) print(thislist) thislist = ["apple", "banana", "cherry"] mylist = thislist.copy() print(mylist) thistuple = ("apple", "banana", "cherry") print(thistuple) mytuple = ("apple", "banana", "cherry") print(type(mytuple)) x = ("apple", "banana", "cherry") y = list(x) y[1] = "kiwi", "orange" x = tuple(y) print(x) #thistuple = ("apple", "banana", "cherry") #del thistuple #print(thistuple) this will raise an error because the tuple no longer exists fruits = ("apple", "banana", "cherry") (green, yellow, red) = fruits print(green) print(yellow) print(red) import pygame import sys # Initialize Pygame pygame.init() # Constants for the game window WIDTH, HEIGHT = 800, 600 FPS = 60 # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) # Player constants PLAYER_WIDTH = 50 PLAYER_HEIGHT = 50 PLAYER_SPEED = 5 JUMP_HEIGHT = 10 # Platform constants PLATFORM_WIDTH = 100 PLATFORM_HEIGHT = 20 # Initialize the display screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Simple Platformer") # Clock for controlling FPS clock = pygame.time.Clock() # Player class class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface((PLAYER_WIDTH, PLAYER_HEIGHT)) self.image.fill(RED) self.rect = self.image.get_rect() self.rect.center = (WIDTH // 2, HEIGHT // 2) self.vel_y = 0 self.on_ground = False def update(self): # Apply gravity self.vel_y += 0.5 self.rect.y += self.vel_y # Check collision with ground if self.rect.bottom >= HEIGHT: self.rect.bottom = HEIGHT self.vel_y = 0 self.on_ground = True else: self.on_ground = False # Check for collisions with platforms platform_collisions = pygame.sprite.spritecollide(self, platforms, False) for platform in platform_collisions: if self.vel_y > 0: self.rect.bottom = platform.rect.top self.vel_y = 0 self.on_ground = True # Player movement keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.rect.x -= PLAYER_SPEED if keys[pygame.K_RIGHT]: self.rect.x += PLAYER_SPEED if keys[pygame.K_SPACE] and self.on_ground: self.jump() def jump(self): self.vel_y = -JUMP_HEIGHT # Platform class class Platform(pygame.sprite.Sprite): def __init__(self, x, y): super().__init__() self.image = pygame.Surface((PLATFORM_WIDTH, PLATFORM_HEIGHT)) self.image.fill(BLACK) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y # Create player object player = Player() # Create platforms platforms = pygame.sprite.Group() platform1 = Platform(0, HEIGHT - 20) platform2 = Platform(WIDTH // 2 - 50, HEIGHT // 2) platfrom3 = Platform(WIDTH // 2 + 60, HEIGHT / 2 + 10) platforms.add(platform1, platform2, platfrom3) # Main game loop running = True while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Update player.update() # Draw screen.fill(WHITE) platforms.draw(screen) screen.blit(player.image, player.rect) pygame.display.flip() # Cap the frame rate clock.tick(FPS) # Quit Pygame pygame.quit() sys.exit()