Snake game
import random # Define game board dimensions width = 40 height = 30 # Initialize snake and food positions snake_x = width // 2 snake_y = height // 2 food_x = random.randint(0, width - 1) food_y = random.randint(0, height - 1) # Initialize snake length and direction snake_length = 1 direction = "up" # Initial direction # Game loop while True: # Print the game board for y in range(height): for x in range(width): if x == snake_x and y == snake_y: print("S", end=" ") # Print "S" for snake head elif x == food_x and y == food_y: print("F", end=" ") # Print "F" for food else: print("#", end=" ") # Print "#" for game boundaries print() # Print a newline after each row # Get user input for direction change new_direction = input("Enter direction (up, down, left, right): ").lower() # Validate and update direction based on user input and current direction if new_direction == "up" and dire