Notes
Booleans:
- A data type in programming representing true or false values.
- Used for making logical decisions and comparisons.
- True: Represents a condition that is considered as “true” or “yes.”
- False: Represents a condition that is considered as “false” or “no.”
Relational Operators:
- Equal to: a = b
- Not equal to: a != b
- Greater than: a > b
- Less than: a < b
- Greater than or equal to: a >= b
- Less than or equal to: a <= b
Conditionals
- Condition statements are fundamental in programming. They consist of:
- Condition: A Boolean expression or logical test.
- True Block: Code executed if the condition is true.
- False Block (optional): Code executed if the condition is false.
Homework
# HW 1 - Voting Eligibility
# Get user input for age
age = int(input("Enter your age: "))
# Check eligibility using boolean logic
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
# HW 2 - Employee Bonus
# Get user input for salary and years of service
salary = float(input("Enter your salary: "))
years_of service = int(input("Enter your years of service: "))
# Calculate bonus
if years_of_service > 5:
bonus = 0.05 * salary
print(f"Your bonus amount is ${bonus:.2f}")
else:
print("You are not eligible for a bonus.")
# HW 3 - Grading System
# Get user input for marks
marks = float(input("Enter your marks: "))
# Determine the grade based on the grading system
if marks < 25:
grade = "F"
elif 25 <= marks < 45:
grade = "E"
elif 45 <= marks < 50:
grade = "D"
elif 50 <= marks < 60:
grade = "C"
elif 60 <= marks < 80:
grade = "B"
else:
grade = "A"
# Print the corresponding grade
print(f"Your grade is: {grade}")