This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Learn some programming basics


Using Wing IDE, you'll learn some of the programming basics that you'll need in order to build your game.

In order to build your game, you'll need to know a few programming basics. Let's learn about them now. The three things you'll need to know are:

1. How to ask a player for information
2. How to store that information
3. How to write a sentence using the player's information

Let's start with #1: Asking a player for information.

- Open Wing IDE, and in the top-left corner, type the following:

first_name = raw_input("Tell me your name, and click enter. ")


- Find the green "play" arrow. Click it. (This starts your game.)

- In the bottom-right corner, play your game.

There! You just figured out how to ask a player for information.

Now, let's figure out how we can store that information. The good news is that we're halfway done. Because you replied with your name, it has been stored as the variable "first_name". You can imagine that we have a jar called "first_name" and your name is inside it. Now, let's figure out how we can tell the computer to tell us what's in the "first_name" jar.

- In the top-left corner of Wing IDE, keep the line you just typed. Click "enter" so that you're on a new line. Type the following:

print first_name

- Click the green "play" arrow again. Play your game in the lower-right corner. Note what happens.

Now, we're on to Step 3: displaying a sentence that uses the player's information.

Instead of just displaying your name when you play the game, imagine we wanted the computer to say, "Thanks! Your name is [your name here]." How would we do that?

- Go back to Wing IDE. On the line where you have the word "print", we're going to add some words. Change that line so that it looks like this:

print "Thanks! Your name is " + first_name

- Click the green "play" arrow. Play your game in the lower-right corner. Note what happens.

- Change the sentence you are "printing". Make it more fun! Copy and paste your code into the discussion below.

You now know the programming basics you'll need in order to build your first game!

Task Discussion


  • Shannon said:

     

    player_name = str (input ('Please type your name and press enter. '))
    print ('Thanks for playing, ' + player_name + '!')
     
    I wasn't excited about trying a new editor so soon after beginning with Python and IDLE, but having Wing track my needed syntax - open quotes and parentheses - is pretty cool. I guess that's the sort of thing IDEs are for, huh?
    on Jan. 20, 2012, 12:41 p.m.
  • Captain_Ahab said:

     

    first_name=input ("What's your name? Type it in and then click enter.\n")
    print ("Sweet!  Hello " +first_name+", it's a pleasure to meet you!")
    on Jan. 18, 2012, 7:06 a.m.
  • Ken Doman said:

    # input user name
    first_name = raw_input('So, what\'s your name? ')
    # greet user
    print('Pleasure to meet you, ' + first_name + '.')

    on Jan. 13, 2012, 3:05 p.m.
  • Sparker said:

     

    first_name = raw_input('Tell me your name and click enter. ')
    print('Thanks! Your name is ' + first_name + '.')
    on Jan. 8, 2012, 5:40 p.m.
  • Landon said:

    # Ask player for information
    first_name = raw_input("Please type your first name. ")
    # Greet player
    print "Thanks " + first_name + "! ", "Nice to meet you"

    Screenshot:

    screenshot of myGame

    on Jan. 3, 2012, 1:49 a.m.
  • Nathan Day said:

    How did you get your get yours to paste in with syntax highlighting?

    Here is a link to my version on pastebin  http://pastebin.com/yv0kzMxA

    on Dec. 26, 2011, 9:39 p.m.
  • Brylie Oxley said:

     

    first_name = raw_input('Please tell me your name: ')
    print "Hi", first_name, "I am glad you are here!"

    on Dec. 23, 2011, 2:01 a.m.