problem with ranges and lists 03-22-2013, 01:46 AM
#1
Hey guys, i started to code a text base game on python but ran in to a problem.
I'm using a list to save different words for directions so the user can type things like east or left to go left.
The line of code that is giving me trouble is.
if direction ==left[range(8)]:
This is the error i get, TypeError: list indices must be integers, not range
Any idea how to fix this?
Here is the rest of the code as well in case that helps.
I'm using a list to save different words for directions so the user can type things like east or left to go left.
The line of code that is giving me trouble is.
if direction ==left[range(8)]:
This is the error i get, TypeError: list indices must be integers, not range
Any idea how to fix this?
Here is the rest of the code as well in case that helps.
Code:
left = 'left LEFT Left east EAST East notright port'.split()
right = 'right RIGHT Right west WEST West notleft starboard'.split()
down = 'down DOWN Down notup south SOUTH South back backward backwards'.split()
up = 'up UP Up north NORTH North notdown forward front '.split ()
name = input('what is your name traveller? \n')
print('helo ',name,' how old are you? ')
age = int(input(''))
if age >20:
whatage = 'old'
else:
whatage = 'young'
print('welcome ',whatage,'adventurer. to the land of coding and games')
direction = input('where would you like to go? \n')
if direction ==left[range(8)]:
print ('you went left')
there are 10 types of people in this world,
those who understand binary and those who don't.
skype name: J4W3S.23
those who understand binary and those who don't.
skype name: J4W3S.23