Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alien game code from book
#1
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.
Reply
#2
Lines 7-12 need to move one space to the left
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I might be doing it wrong but its still saying the same error
Reply
#4
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']))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Ok got that. Thanks for the help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  needing some help to write some code for a game calculator rymdaksel 1 353 Jan-02-2024, 09:56 AM
Last Post: deanhystad
  Problem with my pong game code Than999 8 3,760 May-15-2022, 06:40 AM
Last Post: deanhystad
  Music Selection Game Code WyattH 3 2,375 Jul-20-2020, 11:16 AM
Last Post: ndc85430
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,679 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Restart Error when using code from lesson book Kathleen57 2 2,213 Mar-13-2020, 09:18 PM
Last Post: Kathleen57
  Help for guessing game code Kronos 5 3,215 Mar-09-2020, 04:53 PM
Last Post: snippsat
  Need help - 22000 lines of code / alien writings! gfetng 1 1,884 Feb-22-2019, 03:25 PM
Last Post: ichabod801
  Individuallien attack in alien invasion game runnerpaul 1 2,350 Jul-31-2018, 07:10 AM
Last Post: ThiefOfTime
  pyython code copied 1to1 from book not working. BlackReptile 2 2,852 Feb-21-2018, 02:46 AM
Last Post: abhin
  I am trying to make a Colour Wars game, "Winning code" missing Ondrejoda 0 2,248 Feb-18-2018, 11:06 AM
Last Post: Ondrejoda

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020