Unit 3.5 & 3.8 Hacks
Unit 3.5 & 3.8 Hacks
3.5
Explain in your own words what each logical operator does
- AND determines if both of the statements are true
- OR determines if either one are true, and even if both are true it will still work
- NOT checks if a certain condition is not met, for example no sunny checks to see if its cloudy Code your own scenario that makes sense for each logical operator
# NOT
sun = False
if not sun:
print("it is cloudy!")
# AND
weight = 240
age = 19
if weight >= 150 and age >= 15:
print("You meet the requirements for this ride!")
# OR
emotion = "sad"
if emotion=="sad" or emotion=="lonely":
print("you are depressed")
3.6 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.
- Selection: If something is true a specific code will run. EX: If answer is yes then a code block will run
- Algorithm: a procedure of code that does something or a task. EX: algorithm that takes in your grades and gives out a GPA number
- Conditional statement: runs a function depending or executs if TRUE. EX: if the sun is out, then it is sunny. 1 point for writing a program that uses binary conditional logic. 0.5 points if it is original and shows complexity
import random
numbers = [0,1]
def AND():
num1 = random.choice(numbers)
num2 = random.choice(numbers)
print(num1, "&", num2, "=", num1 & num2)
print("AND")
for i in range(5):
AND()
def OR():
num1 = random.choice(numbers)
num2 = random.choice(numbers)
print(num1, "|", num2, "=", num1 | num2)
print("OR")
for i in range(5):
OR()
def XOR():
num1 = random.choice(numbers)
num2 = random.choice(numbers)
print(num1, "^", num2, "=", num1 ^ num2)
print("XOR")
for i in range(5):
XOR()
3.7
- Create 3 different flow charts representing nested statements and transfer them into code.
BallColor = "red"
size = "7"
if BallColor=="red":
if size !="8":
print("right color wrong size")
elif size == "8":
print("right color and right size")
else:
if size !="8":
print("wrong color wrong size")
elif size == "8":
print("wrong color and right size")
Temp = 79
Humid = True
if Temp > 80:
if Humid == True:
print("it is hot and humid")
elif Humid == False:
print("it is hot and not humid")
elif Temp<80:
if Humid == True:
print("it is not hot and humid")
elif Humid == False:
print("it is not hot and not humid")
if money>30:
if store == "open":
print("you can buy it")
elif store == "closed":
print("You can buy it another day")
else:
print("you do not have enough money")
Create a piece of code that displays four statements instead of three. Try to do more if you can.
if coins>30:
if shop == "open":
print("you can buy it")
elif store == "closed":
print("You can buy it another day")
elif time == "night":
print("come during the day")
else:
print("you cannot buy it")
- Make piece of code that gives three different recommandations for possible classes to take at a scholl based on two different condtions. These conditions could be if the student likes STEM or not.
STEM = True HISTORY = True if STEM: print("Calculus, Physics, Biology") elif HISTORY: print("European History, Gov, american history") else: print("PE, art, english")