age = 15
citisenship= True
if citisenship and age >=18:
#works only if both conditions are true
print(“You can vote”)
else:
print(“You cannot vote”)
#if either condition isnt met
#Define a function to calculate the updated salary based on years of service
def calculate_updated_salary(current_salary, years_of_service):
if years_of_service > 5:
new_salary = current_salary * 1.05 # Increase the salary by 5% if service is more than 5 years
return new_salary
else:
return current_salary # Keep the current salary if service is 5 years or less
#Input the current salary from the user
current_salary = float(input(“Enter your current salary: “))
#Input the number of years of service from the user
years_of_service = int(input(“Enter the number of years you have serviced the company: “))
#Calculate the updated salary
new_salary = calculate_updated_salary(current_salary, years_of_service)
#Check if the salary has changed and print the appropriate message
if new_salary != current_salary:
print(“Your updated salary is: $” + str(new_salary))
else:
print(“No change in your salary. Your current salary is: $” + str(current_salary))
#Input the user’s test score
test_score = int(input(“Please enter your test score: “))
#Determine the grade based on the score
grade = “”
if test_score < 25:
grade = “F”
elif test_score >= 25 and test_score <= 45:
grade = “E”
elif test_score > 45 and test_score <= 50:
grade = “D”
elif test_score > 50 and test_score <= 60:
grade = “C”
elif test_score > 60 and test_score <= 80:
grade = “B”
else:
grade = “A”
#Print the grade
print(“Your grade is:“, grade)
Summary:
Booleans:
Two values: True and False. Used for logical comparisons.
Relational Operators:
Used for comparisons, e.g., equal to, not equal to, greater than, less than.
Popcorn Hack 1:
Example boolean expressions for age, average grade, and temperature checks.
Not Operator:
Flips a condition.
And Operator:
Combines two conditions.
Or Operator:
Returns True if at least one condition is true.
Conditionals:
Control program flow based on conditions. Include a condition, true block, and an optional false block.
Examples 2:
Illustrates conditional statements with elif.
Popcorn Hack 2:
Finds the highest score in a list.
Popcorn Hack 3:
A conditional program that checks age and driving conditions.