0

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

3rd May 2024, 9:52 AM
Abhinav Sharma
3 Antworten
+ 8
Hello, Your code is not complete can you be more specific? what exactly you want at the last line
3rd May 2024, 1:57 PM
Suparna Das
Suparna Das - avatar
+ 4
This won't work on Sololearn. GUI and real-time input aren't possible. If you have trouble with a different python interpreter, then you might need to attach your code like the following guide explains: https://sololearn.com/compiler-playground/Wek0V1MyIR2r/?ref=app https://sololearn.com/compiler-playground/W3uiji9X28C1/?ref=app https://sololearn.com/compiler-playground/W0uW3Wks8UBk/?ref=app
3rd May 2024, 5:14 PM
Ausgrindtube
Ausgrindtube - avatar
0
Make this code work
3rd May 2024, 9:53 AM
Abhinav Sharma