3. Strings, Variables, and User Input
During this lesson, you will learn:
First, let's try out the "interactive" Python console trinket. It's called a console because you can type Python commands into it, and they will be immediately run. It's called a "trinket" because it's created by the trinket company. The ">>>" is called a "prompt", and that's where you type your commands. We've already done a few commands. Some things to try:
- How to manipulate text strings
- How to create and use variables
- How to get information from the user
First, let's try out the "interactive" Python console trinket. It's called a console because you can type Python commands into it, and they will be immediately run. It's called a "trinket" because it's created by the trinket company. The ">>>" is called a "prompt", and that's where you type your commands. We've already done a few commands. Some things to try:
- Try printing out your own text strings. How do you combine two strings?
- Do some math operations. What's the biggest number you can create?
- What happens when you make a mistake?
Now let's create some string variables and add them together. We'll also switch to a stand-alone trinket instead of the console trinket. In the stand-alone trinket, you type all of your commands into the window. Then, once you're happy with the code, click the "Run" button. If something didn't work quite right, you can go back and change your code and click "Run" again.
Try out the following program. Read the comments within the code and see if you can fix the bugs.
Now we'll learn how to get input (or data) from the user of our program. Again, read the comments within the program to see what to do.
Learning Targets
- I can create and use string variables in Python.
- I can explain the difference between the interactive Python console and running a Python script.
- I can get input from the user of a Python program.