3.5-3.7 Notes and Hacks
grade1 = 90
grade2 = 65
grade3 = 60
grade4 = 75
grade5 = 95
totalGrade = grade1 + grade2 + grade3 + grade3 + grade4 + grade5
gradeAvg = totalGrade/5
print(str(gradeAvg) + "% > 80%", gradeAvg>80)
print("1 > 2 or 5 < 12", 1 > 2 or 5 < 12)
# Output TRUE using OR ^
# Output FALSE using NOT
print("24 > 8:", not 24 > 8)
# Output FALSE using AND
print("10 > 20:", 10 > 20)
num1 = 20
num2 = 120
sum = num1 + num2
if sum == 200:
print(sum)
else:
print(sum)
If a person has at least 8 hours, they are experienced If a person is experienced their salary is 90k, if they have ten hours or above their salary 150k If a person is inexperienced their salary is always 50k print the salary of the person at the end and whether they are experienced or not
hours = 8
if (hours < 8)
{
console.log("they are inexperienced and their salary is 50K")
}
else
{
console.log("they are experienced")
if (hours >= 10)
{
console.log("Their salary is 150K")
}
else
{
console.log("Their salary is 90K")
}
}
import random
itemCost = random.randint(0,100)
itemDaysOld = random.randint(0,100)
print("The item is $" + str(itemCost), "and is", str(itemDaysOld), "days old")
if itemDaysOld < 100:
if itemCost < 50:
if itemCost > 25:
print("this is a regular product")
else:
print("this is a cheap product")
else:
print("this product is too expensive")
else:
print("this product is expired")
Quiz
import getpass
q1options = ["A. AND", "B. OR", "C. XOR", "D. NOT"]
q2options = ["A. True and True = ", "B. True and False = ", "C. False and True", "D. False and False"]
ans1 = q1options[2]
ans2 = q2options[0]
x = 5
print("Welcome", getpass.getuser() + "! Beginning quiz.")
print("Question 1: \nSuppose that there is a lightbulb connected to two light switches. When both light switches are on off, the lightbulb does not light up. When only one light switch is on, the lightbulb is on. Finally, when both of the light switches are on, the lightbulb is off. Which logical operator does this lightbulb follow?")
for i in q1options:
print(i)
input1 = input("Please select an option:")
print("you have selected option", str(input1.upper()))
if input1.upper() == ans1[0]:
print("Congratulations! That is correct")
else:
print("Sorry that is incorrect.")
print("Question 2: Let presume that the light switches from Question1 are rewired to follow an AND logical operator. Which of the following would result in the lightbulb turning on?")
for i in q2options:
print(i)
input2 = input("Please select an option:")
print("you have selected option", str(input2.upper()))
if input2.upper() == ans1[0]:
print("Congratulations! That is correct. True and True = "+ True and False)
else:
print("Sorry that is incorrect. The answer is A. True and True which would output", True and False)
print("Question 3: What would not(x < 5 and x < 10) output if x = 5?")
input3 = input()
print("you have answered", str(input3.lower()))
if input3.lower() == "False":
print("Congratulations! That is correct. not(x < 5 and x < 10) would output", not(x < 5 and x < 10))
else:
print("Sorry that is incorrect. The answer is False. not(x < 5 and x < 10) would output", True and False)