Lesson 5-7 Hacks
Hacks
Hacks 1:
- Explain in your own words what each logical operator does AND: returns true if both of the values being compared are true and returns false if either of the values are false. OR: Returns true if either of the conditions are true. And returns false if both of the conditions are false. NOT: Returns true if the following condition is false. Returns false if it is true.
- Code your own scenario that makes sense for each logical operator:
iswindy = True
result = not(iswindy)
print(result)
Hack 2: part 1
- Selection: A selection is a decision or a question. At some point in the program, the computer may need to ask a question because it has reached a point where there are one or more options available
- Algorithm: It is like a recipe. It is lines of codes that a computer follows to solve a problem
- Condition: They are basically a decision making statement in code.
Conditional Statement part 2
for i in range(2):
password = input("Please enter the password")
if password == "python" or password == "Python":
print("Welcome!!")
else:
print("This password is incorrect")
Hack 3:
Create a piece of code that displays four statements instead of three.
def get_week_day(argument):
if(argument == 0):
day="Sunday"
elif(argument == 1):
day="Monday"
elif(argument == 2):
day="Tuesday"
elif(argument == 3):
day="Wednesday"
elif(argument == 4):
day="Thursday"
elif(argument == 5):
day="Friday"
elif(argument == 6):
day="Saturday"
else:
day="Invalid day"
return day
# Driver program
if __name__ == "__main__":
print (get_week_day(3))
print (get_week_day(1))
print (get_week_day(5))
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.
def get_class(argument):
if(argument == 0):
subject="Physics"
elif(argument == 1):
subject="Chemistry"
elif(argument == 2):
subject="Biology"
elif(argument == 3):
subject="AP Calc AB"
elif(argument == 4):
subject="Medical Interventions"
elif(argument == 5):
subject="AP Phsycology"
return subject
# Driver program
if __name__ == "__main__":
print (get_class(2))
print (get_class(3))
print (get_class(4))