Unit 3.5

  • Boolean: used to represent logical propositions, either true or false
    • For example: there are clouds in the sky = True
  • Relational operators
    • For example: age to get drivers license > 16
  • Logical Operators
    • not: displays the opposite of whatever the data is\
    • and: used to evaluate two conditions together
    • or: if one condition is met
sad = False
result = not(sad)
print(result)
True
pass_test = True
age = 18

if pass_test and age >= 16:
    print("Congrats, you get your drivers license!")
Congrats, you get your drivers license!
score = 9
if score == 9 or score == 0:
    print("You did very well on the quiz!")
You did very well on the quiz!
  • Conditionals: allow for the expression of algorithms that utilize selection without a programming language
  • algorithm: the algorithm describes the instructions to complete a task, which done by the graphic with a list of instructions to do
  • Selection: Code that will execute depending on the algorithm condition returning true or false
  • Conditional Statement / If-Statement: Code that is initiated if a statement is true
word = "hello"
vowel_count = 0

for letter in word:
    if letter == "a" or letter == "e" or letter == "i" or letter == "o" or letter == "u":
        vowel_count += 1
print(f"The number of vowels is {vowel_count}.")
The number of vowels is 2
def likes_count(list):
    if len(list) == 0:
        print("no one likes this")
    elif len(list) == 1:
        print(list[0] + " liked this")
    elif len(list) == 2:
        print(list[0] + " and " + list[1] + " liked this")
    elif len(list) == 3:
        print(list[0] + ", " + list[1] + " and " + list[2] + " liked this")
    else:
        print(list[0] + ", " + list[1] + " and 2 others liked this")

list1 = ["Grace", "Claire", "Annika"]
list2 = ["Grace", "Claire", "Annika", "John"]

likes_count(list1)
likes_count(list2)
Grace, Claire and Annika liked this
Grace, Claire and 2 others liked this

Unit 3.7

photo photo photo

weather_sunny = True
weather_rainy = False
weather_cold = True
weather_hot = False

if weather_sunny:
    print("wear sunscreen")
else:
    if weather_rainy:
        print("Bring an umbrella")
    else:
        if weather_cold:
            print("Wear a sweater")
        else:
            if weather_hot:
                print("Wear a tank top")
            else:
                print("Wear short sleeves")
wear sunscreen
if input("Do you like stem") == "yes":
    if input("Do you like experiments or numbers") == "numbers":
        print("You should take math")
    else:
        if input("do you like living things?") == "yes":
            print("Take biology")
        else:
            print("take physics or chemistry")
else:
    if input("Do you like learning about dead people or writng?") == "writing":
        print("You should take english")
    else:
        print("You should take history")
You should take math
if input("Do you like Taylor Swift?") == "yes":
    if input("What is your favorite album?") == "folklore":
        print("Samzies")
    else:
        print("Ok, understandable")
else:
    if input("Do you like Kanye West?") == "yes":
        print("We can never be friends")
    else:
        print("Good, you should listen to TS")
if input("Are you interested in STEM?") == "yes":
    print("You should take calculus, biology, chemistry, or physics")
else:
    print("You should take APEC, APUSH, or AP Government")