1st Hacks

  • Explain in your own words what each logical operator does
    • NOT: Essentially creates the opposite of what a true/false statement is. For example, is something is set to True, using NOT will make the outcome false
    • AND: Looks for conditions and judges whether the conditions are met or not
    • OR: Looks at a set of conditions and only determines if at least one condition is met
  • Code your own scenario that makes sense for each logical operator
Awake = True
result = not(Awake)
print(result)

# Example of AND

age = 21
if age > 18 and age >= 21:
    print("Congratulations! You are legally an adult that can drink!")

# Example of OR

money = 10
time = 30

if money > 5 or time >= 30:
    print("You've worked for long enough and you have enough money.")
False
Congratulations! You are legally an adult that can drink!
You've worked for long enough and you have enough money.

Second Hacks

Hacks

  • 1 point for defining all the key terms in your own words. 0.5 points if you use examples that show you truly understand it.
  • 1 point for writing a program that uses binary conditional logic. 0.5 points if it is original and shows complexity
  • 1 extra point for each challenge that you program or pair program.
  • 0.5 points for your review ticket looking nice, or you convincing me that it does.
  • 1 point for each and any extra work you do that helps show your understanding of conditionals.
Level I: Vowel Count

Return the number (count) of vowels in the given string. We will consider a, e, i, o, u as vowels for this challenge (but not y). The input string will only consist of lower case letters and/or spaces.

Hint: If you use a lot of if-statements and there are more than one outcome, that is to be expected. If not, don't panic, just keep trying.

vowel = ("aeiou")
word = input("Insert a word to get its vowel checked") # I am going to use the word Canton
a = 0

for alphabet in word:
    if alphabet in vowel:
        a = a + 1

print(a)
2
Level II: Who Likes It?

You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.

Implement the function which takes an array containing the names of people that like an item. It must return the display text as shown in the examples:

[] --> "no one likes this"

["Peter"] --> "Peter likes this"

["Jacob", "Alex"] --> "Jacob and Alex like this"

["Max", "John", "Mark"] --> "Max, John and Mark like this"

["Alex", "Jacob", "Mark", "Max"] --> "Alex, Jacob and 2 others like this"

Likes = ["Peter", "Amanda", "Cynthia"]
Dislikes = [ "Jake"]
Neutral = ["Steven", "Tracer"]


Post = [Likes, Dislikes, Neutral]
for Item in Post:
    for Item in Item:
        if Item in Likes:
            print(str(Item) + " likes this post")
        elif Item in Dislikes:
            print(str(Item) + " does not like this post")
        elif Item in Neutral:
            print(str(Item) + " has not seen this post yet")
Peter likes this post
Amanda likes this post
Cynthia likes this post
Jake does not like this post
Steven has not seen this post yet
Tracer has not seen this post yet
num = 3
num2 = [1, 3, 5, 7, 9, 11]

for item in num2:
    if item + num >= 10:
        display("More than 10")
    else:
        display("Less than 10")
'Less than 10'
'Less than 10'
'Less than 10'
'More than 10'
'More than 10'
'More than 10'

Key Terms (1 Point):

  • Selection: Basically gives the computer options that will return an action (true or false) depending on the given conditions are met or not. Ex: It's raining, and the selection is 'It it raining?' (Yes, then go outside) or (No, stay at home).

  • Algorithm: A set of instructions that are to be carried out by the computer to achieve a certain goal. Example: To find out the solution to (8 5 / 2) + 1 , the computer must first solve for 85, THEN divide that product by 2, and then FINALLY add 1 to find the solution.

  • Conditional Statement (If-statements): Something that gives the computer a statement (condition) that will affect its sequence of actions based on if it is met (true) or not (false). The if statement is an example of this. Going back to the original statement, a conditional statement would be: "if it is not raining, go outside. else: stay at home."

3rd Hacks

a = 1
b = 2

if a == b:
    print("Equal")
else:
    if a > b:
        print("A is greater than B")
    elif a < b:
        print("B is greater than A")
B is greater than A
Likes = ["Sterling"]
Dislikes = [ "Lindsey"]
Neutral = ["Jacob", "Owen"]


Post = [Likes, Dislikes, Neutral]
for Item in Post:
    for Item in Item:
        if Item in Likes:
            print(Item + " likes y")
        elif Item in Dislikes:
            print(Item + " does not like y")
        elif Item in Neutral:
            print(Item + " has not interacted with y")
Sterling likes y
Jake does not like y
Steven has not interacted with y
Tracer has not interacted with y
burger = 6
hotdog = 4
fries = 3
money = [6, 4, 10, 2, 3]

for i in money:
    if i >= 6:
        print("you can buy a burger")
    else:
        if i >= 4:
            print("you can buy a hotdog")
        else:
            if i >= 3:
                print("you can buy fries")
            else:
                print("you're broke")
you can buy a burger
you can buy a hotdog
you can buy a burger
you're broke
you can buy fries
burger = 6
hotdog = 4
fries = 3
money = [6, 4, 10, 2, 3]

for i in money:
    if i >= 6:
        print("you can buy a burger")
    elif i >= 4:
        print("you can buy a hotdog")
    elif i >= 3:
        print("you can buy fries")
    else: 
        print("you're broke")
you can buy a burger
you can buy a hotdog
you can buy a burger
you're broke
you can buy fries
stem = ["Biology", "Math", "Engineering"]
not_stem = ["pe", "off_role"]

expelled = ["Alex"]
love = ["Alex", "Daniel"]
dislike = ["kim", "elliot"]

list = [love, dislike, expelled]

if item in expelled:
    print(item + " cannot take these courses")


for item in list:
        for item in item:
            if item in expelled:
                (item + " cannot take these courses")
            elif item in love:
                print(item + " should take the following classes: " + str(stem))
            elif item in dislike:
                print(item + " should take the following classes: " + str(not_stem))
Alex cannot take these courses
Daniel should take the following classes: ['Biology', 'Math', 'Engineering']
kim should take the following classes: ['pe', 'off_role']
elliot should take the following classes: ['pe', 'off_role']