Logical Operators Hacks

NOT: this operator displays the exact opposite of what the data indicates

AND: used to evaluate 2 conditions at the same time and checks if both conditions are met

OR: USed to evaluate 2 conditions at the same time, but only checks if one condition is met

isRunning = False
result = not isRunning
print(result)
True
age = 16
if age > 12 and age < 20:
   print("You are a Teenager")
You are a Teenager
teams = 1
score = 2
if teams < 2 or score > 4:
   print("Your team won!")
Your team won!

Conditionals

Selection: when the algorithm only executes depending if the conditions returns true or false

Algorithm: a set of instructions to accomplish a task

Conditional Statement: A statement that affects the sequence of an algorithm depending of the value of a boolean.

num = list(input("Input a binary number: "))
x = 0

for i in range(len(num)):
	digit = num.pop()
	if digit == '1':
		x = x + pow(2, i)
print("The decimal value of the number is", x)

Level One Challenge

text = "Hi my name is Amay"
for char in text:
   if char == "a" or char == "e" or char == "i" or char == "o" or char == "u" or char == "A":
      print(char)
#if text == a or text == e or text == i or text == o or text == u
i
a
e
i
A
a

Level two challenge

array = []
array.append("Amay")
array.append("Safin")
if len(array) == 0:
   print("No one likes it")
else:
   print(" and ".join(array) + " liked it")
Amay and Safin liked it

Nested Statements

isRaining = True
temp = 40
if (isRaining):
   if temp <  45 :
      print("Wear multiple layers.")
   else:
      print("Wear whatever you want bruh")
else:
   print("What is the weather like?")
Wear multiple layers.
isRaining = True
temp = 70
if (isRaining):
   if temp <  45:
      print("Wear multiple layers.")
   else:
      print("Wear whatever you want bruh")
else:
   if isRaining == False:
      print("is it sunny or snowing?")
   else: 
      print("what is the weather like?")
Wear whatever you want bruh
bruh = input("Do you like stem?")
bruhh = input("Do you like science?")
if bruh == "Yes":
   if bruhh == "Yes":
      print("You would like classes like AP Bio and AP Chem.")
   else:
      print("You could take english for better results.")
else :
   print("You might be better off taking classes like ")
You would like classes like AP Bio and AP Chem.