Skip to content

Introduction to Python

Provided Files

Example Code

Model 1 – copy into the editor, save as hello.py

# display a welcome message
print("Welcome to Python 3!")

# give the user a compliment
name = input("What's your name? ")
print(name, "is a great name!")

Model 2 – copy one line at a time into the shell

input("enter the mass in grams: ")
mass = input("enter another mass in grams: ")
mass
unit = input("enter the units for mass: ")
print(mass, unit)
print(mass / 2)
ten = 10
print(ten / 2)
abs(-1)
abs(-1 * ten)

Model 3 – copy one line at a time into the shell

data = 12
data
Data
Data = 34
data
Data
3data = "hello"
data3 = "world"
data3 = hello
hot = 273 + 100
273 + 100 = hot
hot
hot - 100