3.5 - 3.7 hacks
this post is regarding the hacks for topics 3.5 - 3.7
# username is noor
# score is 25
# gameover is false
username = "noor"
score = 25
gameover = False
# AND: true example
AND = username == "noor" and score > 20
print(AND)
# NOT: true example
NOT = not username == "joe"
print(NOT)
# OR: true example
OR = score > 20 or username == "joe"
print(OR)
Hacks 2:
- Selection: basically selecting which part of an algorithm to execute based on an input or other parameter
- Algorithm: set of procedures that is created to solve a specific problem (problem can be anything; problem doesn't need to be a critical one)
- Conditional statement: instructs the code to make a decision based on a true or false condition
x = 9
if x % 2 == 0:
print("this is an even number!")
else:
print("this is an odd number")
number = 10
second_number = 10
first_array = []
second_array = [1,2,3]
if number > 15:
print("1")
if first_array:
print("2")
if len(second_array) == 2:
print("3")
if len(first_array) + len(second_array) == 5:
print("4")
if first_array and first_array[0] == 1:
print("5")
if not second_number:
print("6")
Solution:
number = 16
second_number = 6
first_array = [1,2,3]
second_array = [3,2]
if number > 15:
print("1")
if first_array:
print("2")
if len(second_array) == 2:
print("3")
if len(first_array) + len(second_array) == 5:
print("4")
if first_array and first_array[0] == 1:
print("5")
if not second_number:
print("6")
if money < 100:
if item == "in stock":
print("item is available for purchase")
if itemprice > money:
print("item can't be purchased")
elif itemprice <= money:
print("item can be purchased")
else:
print("item is not in stock")
temp = 65
bringjacket = True
if temp < 65:
if bringjacket == True:
print("its really cold! Good thing you brought your jacket")
elif bringjacket == False:
print("its really cold and you should have brought your jacket!")
elif temp >= 65:
if bringjacket == False:
print("its warm, you don't need a jacket right now anyways")
else:
print("its really hot!")
stem = ["Honors POE", "Calculus", "APCSP"]
arts = ["3d animation", "AP music theory", "photography"]
PE = ["weightlifting", "racket sports", "field sports"]
x = input("what is your preferred course pathway?")
if x == "stem":
print(stem)
elif x == "arts":
print(arts)
else:
print(PE)
The code above counts for both the flow chart section and classes section of the hacks. Code that can display four statements is below:
if money < 100:
if item == "in stock":
print("item is available for purchase")
if itemprice > money:
print("item can't be purchased")
elif itemprice <= money:
print("item can be purchased")
else:
print("item is not in stock")