In [1]:
print("Hello World!")
print("Hello Again")
print("I like typing this.")
print("This is fun.")
print('Yay! Printing.')
print("I'd much rather you 'not'.")
print('I "said" do not touch this.')
In [ ]:
'''
Notes:
octothorpe, mesh, or pund #
'''
In [3]:
# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.
print("I could have code like this.") # and the comment after is ignored
# You can also use a comment to "disable" or comment out code:
# print("This won't run.")
print("This will run.")
In [5]:
# BODMAS
print("I will now count my chickens:")
print("Hens", 25 + 30 / 6)
print("Roosters", 100 - 25 * 3 % 4)
print("Now I will count the eggs:")
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
print("Is it true that 3 + 2 < 5 - 7?")
print(3 + 2 < 5 - 7)
print("What is 3 + 2?", 3 + 2)
print("What is 5 - 7?", 5 - 7)
print("Oh, that's why it's False.")
print("How about some more.")
print("Is it greater?", 5 > -2)
print("Is it greater or equal?", 5 >= -2)
print("Is it less or equal?", 5 <= -2)
In [6]:
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven
print("There are", cars, "cars available.")
print("There are only", drivers, "drivers available.")
print("There will be", cars_not_driven, "empty cars today.")
print("We can transport", carpool_capacity, "people today.")
print("We have", passengers, "to carpool today.")
print("We need to put about", average_passengers_per_car,
"in each car.")
In [7]:
# assigning variables in a single line
a = b = c = 0
# this seems easier but when using basic objects like arrays or dictionaries it gets wierder
l1 = l2 = []
l1.append(1)
print(l1, l2)
l2.append(2)
print(l1, l2)
# Here list objects l1 and l2 are names assigned to the same memory location. It works different from following
# code
l1 = []
l2 = []
l1.append(1)
print(l1, l2)
l2.append(2)
print(l1, l2)
In [ ]:
my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 # lbs
my_eyes = 'Blue'
my_teeth = 'White'
my_hair = 'Brown'
print(f"Let's talk about {my_name}.")
print(f"He's {my_height} inches tall.")
print(f"He's {my_weight} pounds heavy.")
print("Actually that's not too heavy.")
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee.")
# this line is tricky, try to get it exactly right
total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")
In [ ]:
# f'' format string
In [ ]:
# converting inches to pounds
def inches_to_centi_meters(inches):
centi_meters = inches * 2.54
return centi_meters
def pounds_to_kilo_grams(pounds):
kilo_grams = pounds * 0.453592
return kilo_grams
inches = 1.0
pounds = 1.0
print(inches, inches_to_centi_meters(inches))
print(pounds, pounds_to_kilo_grams)