Article Outline
Python example 'lesson3-NumbersAndMath'
lesson3-NumbersAndMath
Python beginners example: lesson3-NumbersAndMath
# Variables do not have to contain strings of text. They can also contain
# number values.
# You still create variables with the equal sign just like before. These
# variables contain integers, or 'int's as they are called in python
cars = 9
trucks = 10
# Another numeric variable type is the floating point number, or 'float'. A
# float does not have to be a whole number. It can also be a decimal.
myHeight = 174.3
yourHeight = 181.0
# We can print(ints and floats using the print() function just like strings.)
print("Number of cars in the parking lot: ")
print(cars)
print("My height in centimeters: ")
print(myHeight)
# We can also do math with ints and floats.
totalVehicles = cars + trucks
heightDifference = yourHeight - myHeight
# And we can print(the results.)
print("Total vehicles in the parking lot: ")
print(totalVehicles)
print("Difference between our heights: ")
# Let's calculate the percentage of vehicles that are cars.
# percentCars =
# ----------- Exercises Below -----------------
# 1. Add a print(statement on line 29 to print(the height difference that we)
# calculated on line 23
# 2. There are lots of other math operators such as:
# * for multiplication
# / for division
# ** for exponentiation
# Uncomment line 32 and compute the percentage of vehicles that are cars
# then print(the result.)
Useful links
- Learn Python: https://pythonbasics.org
- Download Python: https://python.org