quhluh

Python code snippet that simulates walking in a grid-like environment

Dec 3rd, 2024
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. # Simple Walking Simulation
  2. def display_position(x, y):
  3.     print(f"Current Position: ({x}, {y})")
  4.  
  5. def main():
  6.     print("Welcome to the Walking Simulator!")
  7.     print("Use W (up), A (left), S (down), D (right) to move. Type 'quit' to exit.")
  8.    
  9.     # Starting position
  10.     x, y = 0, 0
  11.     display_position(x, y)
  12.    
  13.     while True:
  14.         # Get user input
  15.         move = input("Move (W/A/S/D): ").lower()
  16.        
  17.         if move == "w":
  18.             y += 1
  19.         elif move == "a":
  20.             x -= 1
  21.         elif move == "s":
  22.             y -= 1
  23.         elif move == "d":
  24.             x += 1
  25.         elif move == "quit":
  26.             print("Exiting Walking Simulator. Goodbye!")
  27.             break
  28.         else:
  29.             print("Invalid input! Use W, A, S, D to move or 'quit' to exit.")
  30.             continue
  31.        
  32.         # Display new position
  33.         display_position(x, y)
  34.  
  35. if __name__ == "__main__":
  36.     main()
Advertisement
Add Comment
Please, Sign In to add comment