Show 02: Strings, Integers, and Floats

Before you can use software to solve real-world problems, you have to get more familiar with Python. It will take practice and will be hard and confusing, but it will be worth it.

Open a new script in Canopy. Type in the following code exactly. Remember, do not copy and paste.

Note

For this and future exercises, I will not show you screenshots of my computer screen. Instead, I'll show you the code like below, which you will type in to your computer.

print "The average temp in PHX in May is %s F" % 93.6
print "Convert degrees F to C. Google an equation."

# This is your first *real* equation in Python.
print (93.6 - 32) / 1.8

print "" # What does this line do?

print "Convert temp back to F."
print "Now converting 34.222 C to F: %s" % (34.22 * 1.8 + 32)

Save this file as ex2-phoenix_weather.py. Then click Run.

(That _ character is called "underscore". Look up how to type it with your keyboard. On my keyboard I press Shift + -.)

What you should see

Here is what the output of that program would look like:

The average temp in PHX in May is 93.6 F
Convert degrees F to C. Google an equation.
34.2222222222

Convert temp back to F.
Now converting 34.222 C to F: 93.596

Study Drills

  • In the code you typed above, what do you think the %s does? See if you can change what appears in the %s locations without modifying a %s.