I can't figure out what's wrong with this code. This is the third coding language I've learned, so maybe it's a syntax error? This is just the moving section:
I'm trying to get it to change currentposition when you move, then tell you where you moved to. Instead it kept saying "Sorry, this space does not exist" no matter what.
possibleplace = [11, 12, 13, 14, 15, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, 41, 42, 43, 44, 45, 51, 52, 53, 54, 55]
currentposition = 11
def movenorth(currentposition):
ismovingnorthpossible = (currentposition - 10) in possibleplace
if ismovingnorthpossible:
currentposition = currentposition - 10
return "You have moved North"
else:
return "Sorry, this space does not exist."
def moveeast(currentposition):
ismovingeastpossible = (currentposition + 1) in possibleplace
if ismovingeastpossible:
currentposition = currentposition + 1
return "You have moved East"
else:
return "Sorry, this space does not exist."
def movewest(currentposition):
ismovingwestpossible = (currentposition - 1) in possibleplace
if ismovingwestpossible:
currentposition = currentposition - 1
return "You have moved West"
else:
return "Sorry, this space does not exist."
def movesouth(currentposition):
ismovingsouthpossible = (currentposition + 10) in possibleplace
if ismovingsouthpossible:
oldposition = currentposition
currentposition = oldposition + 10
return "You have moved South"
else:
return "Sorry, this space does not exist."
action = input("Type s, south, or go south to move south, etc. (you get 1000 moves!) ")
if action.lower() == 'north' or action.lower() == 'n' or action.lower() == "move north":
currentposition = movenorth(currentposition)
print(currentposition)
numofturnsleft = 1000
while numofturnsleft > 0:
action = input("")
numofturnsleft -= 1
print(numofturnsleft)
print(movenorth(currentposition))
if action.lower() == 'south' or action.lower() == 's' or action.lower() == "move south":
currentposition = movesouth(currentposition)
print(currentposition)
print(movesouth(currentposition))
if action.lower() == 'west' or action.lower() == 'w' or action.lower() == "move west":
currentposition = movewest(currentposition)
print(currentposition)
print(movewest(currentposition))
if action.lower() == 'east' or action.lower() == 'e' or action.lower() == "move east":
currentposition = moveeast(currentposition)
print(currentposition)
print(moveeast(currentposition))