Last time I showed you how to use variables to vary the output of your programs. But that’s only part of it. You and I both know the magic happens when you can get user input. Awww yeah.
Open up a text editor and type the following:
user_input = raw_input() print user_input
Now save it as input.py, navigate to the directory you saved it in, and type
You should now see…. nothing!
The point is to get your input after all. Finally, you can make the computer listen to you. Go ahead and type whatever you want. I’m going to type “potato pancakes”.
Now hit the enter key and watch what happens
potato pancakes potato pancakes
Did you see that?! You have now programmed your own virtual parrot! Let’s try it a few more times:
Cookies are an all-the-time food Cookies are an all-the-time food
I am so great! I am so great!
You see! The computer has no choice! It has to repeat whatever you say!!