Python Forum

Full Version: Alien game code from book
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im still on my book and got stuck at this code.


alien_0 = {'x_position': 0, 'y_poaition': 25, 'speed': 'medium'}
print('original x-position: ' + str(alien_o['x_position']))

#Move the alien to the right.
#Determine how far to move the alien based on its current speed.
if alien_0['speed'] =='slow':
	x_increment = 1
 elif alien_0['speed'] == 'medium':
	 x_increment = 2
 else:
	 # This must be a fast alien
	 x_increment = 3
 
 
# The new position is the old position plus the increment.
alien_0['x_position'] = alien_0['x_position'] + x_increment

print('new x_position: ' +str(alien_0['x_position']))
Comes up with this
[Image: cQ0pua9.png]

I tried moving the elif and else more left or right but it just changes the error then.
Any ideas i'm still newish at this but having trouble with making sure the (if, elif and else) are in the right places.
Lines 7-12 need to move one space to the left
I might be doing it wrong but its still saying the same error
Sorry, my bad. It was just lines 8-12. line 7 was OK. Note also there is misspelled variable name on line 2

alien_0 = {'x_position': 0, 'y_poaition': 25, 'speed': 'medium'}
print('original x-position: ' + str(alien_0['x_position']))
 
#Move the alien to the right.
#Determine how far to move the alien based on its current speed.
if alien_0['speed'] =='slow':
    x_increment = 1
elif alien_0['speed'] == 'medium':
    x_increment = 2
else:
    # This must be a fast alien
    x_increment = 3
  
  
# The new position is the old position plus the increment.
alien_0['x_position'] = alien_0['x_position'] + x_increment
 
print('new x_position: ' +str(alien_0['x_position']))
Ok got that. Thanks for the help.