社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Carl_M

Carl_M 最近回复了
# The Commands are going North and South in the Y - variable and East and West in the X - variable and X - to exit the game
x = 0
y = 0
print("Welcome to sloth quest!")
print("________________________________________")
print()

print("You're currently at position (0, 0) in the world.")
print(
    "Available commands: N - go north, S - go south, E - go east, W - go west, X - exit game")
while True: # run untill the user enters X
    # limit play area to -5 x 5
    command = input("Enter a command: ")
    command = command.upper() # Ensure user input is upper case
    if command == ("N"):
        y = y + 1
    elif command == ("E"):
        x = x + 1
    elif command == ("S"):
        y = y - 1
    elif command == ("W"):
        x = x - 1
    elif command == 'X': # Exit the loop
         break
    if x < -5 or x > 5 or y < -5 or y > 5:
        # What should happen?
        print("error you have left the play area")
print('Thanks for playing') # Exit the game.
# I want to make a loop so that these commands can be input together so that the goal or hazard is reached.