Input, Output, and Variables

Today introduces you to a basic Python program that illustrates how to print to the screen, read from the user, and store the user's input into a variable. These are basic input/output techniques that you'll have in most of your future programs.

Read Chapter 2 (until "Choosing mnemonic variable names")

Link to the online textbook.

You will learn about variables and types.

Today in Class

We will discuss and learn about:

You should be able to understand these programs.

A simple output and input program.

# Output and input from the user.
print("Hello friend!")
name = input("What is your name? ")
print("Hello " + name)
print("My name is Pythoner")

A program to convert temperature units.

# Input current temperature in F.
fah = input("Enter temp in Fahrenheit: ")
fah = int(fah)  # Why do we need this line?

# Convert to Celsius.
cel = (fah-32) * (5/9)

# Print the result.
print("That is " + str(cel) + " degrees Celsius")

Try running it!

Try running the above using the online Python interpreter from a website! As long as you have a Web connection, you can access a Python interpreter. Our recommended site is here:

Copy the program above and paste into the right panel. Then click the green "Run" button above it. You'll see the program run on the right, and you can type in your name or current temperature.