Week 1 Notes
A collection of information referenced from "Python Hello". Consider this my "Anatomy of Python" _notebooks Hack.
print("This is the static text produced.")
print("It can be found within the quotation marks in the parentheses.")
You can also add variables to the printed static text with the "+" symbol.
x = 5 + 3
print("The sum of 5 and 3 is " + str(x) + ".")
This is just scratching the surface.
"if" and "else"
The "if" and "else" commands can make certain things happen under certain conditions.
Instead of giving a copius amount of examples, just know that anything you can make happen unconditionally with Python can be restricted to occur under only certain situations with "if." How to handle the remaining cases is determined by "else," which doesn't necessarily have to be present.
x = 4 * 3
# Remember to use a colon at the end of the "if" statement to activiate the condition.
if x == 12:
print("Four times three is 12.")
else:
print("Something went wrong.")
# We use "else" above for when x is equal to something different.
from tkinter import Y
x = input("What is your favorite number?")
# Fastpages does not allow one to input a response in the actual page.
# For the sake of demonstration, 'x' has been set to equal 5.
# The syntax looks like this if you want a separately printed question and response.
print("What is your other favorite number?")
y = input()
# The variable 'y' has been set to equal 3.
# Now the "if" command will vary based on what we said.
z = int(x) * int(y)
if z == 12:
print("The product of your favorite numbers is 12.")
else:
print("The product of your favorite numbers is not 12.")
x = input("What is your favorite number?")
y = input("What is your second favorite number?")
z = int(x) * int(y)
if z == 12:
print("The product of your favorite numbers is 12.")
elif z == 15:
print("The product of your favorite numbers is 15.")
else:
print("The product of your favorite numbers is not 12 or 15.")