﻿ Lesson 05: Logical Operators

Regular Operators

Introduction

As introduced in the previous lesson, a logical comparison is used to establish the logical relationship between two values, a variable and a value, or two variables. There are various operators available to perform such comparisons.

Practical Learning: Introducing Comparisons

1. Start Microsoft Visual Studio and create a new Python Application named Exercise05
2. In the empty document, type the following code:
```print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Item Preparation")
print("-------------------------------------------------------")
print("Enter the following pieces of information")
print("-------------------------------------------------------")

discount_rate   : int   = 75
discount_amount : float = 0.00

item_name : str = input("Item Name:        ")
original_price : float = float(input("Original Price:   "))
days_in_store : int    = int(input("Days in Store:    "))

discount_amount  = original_price * discount_rate / 100
discounted_price = original_price - discount_amount

print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+")
print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Store Inventory")
print("-------------------------------------------------------")
print(f"Item Name:       ", item_name)
print(f"Original Price:  ", original_price)
print(f"Days in Store:   ", days_in_store)
print(f"Discount Rate:   ", discount_rate, "%")
print(f"Discount Amount:  {discount_amount:5.2f}")
print(f"Discounted Price: {discounted_price:5.2f}")
print("=======================================================")```
4. When requested, for the item name as Tulip Sleeved Sheath Dress and press Enter
5. For the original price, type 89.95 and press Enter
6. For the days in store, type 28 and press Enter
```FUN DEPARTMENT STORE
=======================================================
Item Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Item Name:        Tulip Sleeved Sheath Dress
Original Price:   89.95
Days in Store:    28
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Store Inventory
-------------------------------------------------------
Item Name:        Tulip Sleeved Sheath Dress
Original Price:   89.95
Days in Store:    28
Discount Rate:    75 %
Discount Amount:  67.46
Discounted Price: 22.49
=======================================================
Press any key to continue . . .```

A Value Less Than Another: <

To find out whether one value is lower than another, the operator to use is <. Its formula is:

`Value1 < Value2`

This operation can be illustrated as follows:

Practical Learning: Comparing for a Lesser Value

1. Change the document as follows:
```print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Item Preparation")
print("-------------------------------------------------------")
print("Enter the following pieces of information")
print("-------------------------------------------------------")

discount_rate   : int   = 75
discount_amount : float = 0.00

item_name : str = input("Item Name:        ")
original_price : float = float(input("Original Price:   "))
days_in_store : int    = int(input("Days in Store:    "))

if days_in_store < 60:
discount_rate = 50
if days_in_store < 45:
discount_rate = 35
if days_in_store < 35:
discount_rate = 15
if days_in_store < 15:
discount_rate = 0

discount_amount  = original_price * discount_rate / 100
discounted_price = original_price - discount_amount

print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+")
print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Store Inventory")
print("-------------------------------------------------------")
print(f"Item Name:       ", item_name)
print(f"Original Price:  ", original_price)
print(f"Days in Store:   ", days_in_store)
print(f"Discount Rate:   ", discount_rate, "%")
print(f"Discount Amount:  {discount_amount:5.2f}")
print(f"Discounted Price: {discounted_price:5.2f}")
print("=======================================================")```
3. When requested, for the item name as Tulip Sleeved Sheath Dress and press Enter
4. For the original price, type 89.95 and press Enter
5. For the days in store, type 28 and press Enter
```FUN DEPARTMENT STORE
=======================================================
Item Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Item Name:        Tulip Sleeved Sheath Dress
Original Price:   89.95
Days in Store:    28
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Store Inventory
-------------------------------------------------------
Item Name:        Tulip Sleeved Sheath Dress
Original Price:   89.95
Days in Store:    28
Discount Rate:    15 %
Discount Amount:  13.49
Discounted Price: 76.46
=======================================================
Press any key to continue . . .```
8. When requested, for the item name as Tulip Sleeved Sheath Dress and press Enter
9. For the original price, type 89.95 and press Enter
10. For the days in store, type 46 and press Enter
```FUN DEPARTMENT STORE
=======================================================
Item Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Item Name:        Tulip Sleeved Sheath Dress
Original Price:   89.95
Days in Store:    46
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Store Inventory
-------------------------------------------------------
Item Name:        Tulip Sleeved Sheath Dress
Original Price:   89.95
Days in Store:    46
Discount Rate:    50 %
Discount Amount:  44.98
Discounted Price: 44.98
=======================================================
Press any key to continue . . .```
12. Click inside the document and press Ctrl + A to select everything
13. Type the code as follows:
```print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Payroll Preparation")
print("-------------------------------------------------------")
print("Enter the following pieces of information")
print("-------------------------------------------------------")
print("Employee Information")
first_name : str= input("First Name:    ")
last_name : str  = input("Last Name:     ")
h_sal : float = float(input("Hourly Salary: "))
print("-------------------------------------------------------")
print("Time worked")
print("-------------------------------------------------------")
mon : float = float(input("Monday:        "))
tue : float = float(input("Tuesday:       "))
wed : float = float(input("Wednesday:     "))
thu : float = float(input("Thursday:      "))
fri : float = float(input("Friday:        "))

time_worked : float = mon + tue + wed + thu + fri
net_pay     : float = h_sal * time_worked

print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+")
print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Payroll Evaluation")
print("=======================================================")
print("Employee Information")
print("-------------------------------------------------------")
print(f"Full Name:     {first_name} {last_name}")
print(f"Hourly Salary: {h_sal:5.2f}")
print("=======================================================")
print("Work Preparation")
print('--------+---------+-----------+----------+-------------')
print(" Monday | Tuesday | Wednesday | Thursday | Friday")
print('--------+---------+-----------+----------+-------------')
print(f" {mon:5.2f}{tue:8.2f}{wed:12.2f}{thu:12.2f}{fri:10.2f}")
print("=======================================================")
print("\t\t\tPay Summary")
print("-------------------------------------------------------")
print(f"\t\t\tTotal Time:\t{time_worked:5.2f}")
print("-------------------------------------------------------")
print(f"\t\t\tNet Pay:   \t{net_pay:6.2f}")
print("=======================================================")```
15. When requested, type each of the following values and press Enter each time:
 First Name: Michael Last Name: Carlock Hourly Salary: 28.25 Monday 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 6.5
```FUN DEPARTMENT STORE
=======================================================
Payroll Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Employee Information
First Name:    Michael
Last Name:     Carlock
Hourly Salary: 28.25
-------------------------------------------------------
Time worked
-------------------------------------------------------
Monday:        7
Tuesday:       8
Wednesday:     6.5
Thursday:      8.5
Friday:        6.5
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Payroll Evaluation
=======================================================
Employee Information
-------------------------------------------------------
Full Name:     Michael Carlock
Hourly Salary: 28.25
=======================================================
Work Preparation
--------+---------+-----------+----------+-------------
Monday | Tuesday | Wednesday | Thursday | Friday
--------+---------+-----------+----------+-------------
7.00    8.00        6.50        8.50      6.50
=======================================================
Pay Summary
-------------------------------------------------------
Total Time:     36.50
Net Pay:        1031.12
=======================================================
Press any key to continue . . .```
18. When requested, type each of the following values and press Enter each time:
 First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 Monday 9.50 Tuesday: 8 Wednesday: 10.50 Thursday: 9 Friday: 10.50
```FUN DEPARTMENT STORE
=======================================================
Payroll Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Employee Information
First Name:    Catherine
Last Name:     Busbey
Hourly Salary: 24.37
-------------------------------------------------------
Time worked
-------------------------------------------------------
Monday:        9.5
Tuesday:       8
Wednesday:     10.5
Thursday:      9
Friday:        10.5
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Payroll Evaluation
=======================================================
Employee Information
-------------------------------------------------------
Full Name:     Catherine Busbey
Hourly Salary: 24.37
=======================================================
Work Preparation
--------+---------+-----------+----------+-------------
Monday | Tuesday | Wednesday | Thursday | Friday
--------+---------+-----------+----------+-------------
9.50    8.00       10.50        9.00     10.50
=======================================================
Pay Summary
-------------------------------------------------------
Total Time:     47.50
Net Pay:        1157.58
=======================================================
Press any key to continue . . .```

A Value Greater Than Another: >

To find out if one value is greater than the other, the operator to use is >. Its formula is:

`value1 > value2`

Both operands, in this case value1 and value2, can be variables or the left operand can be a variable while the right operand is a constant. If the value on the left of the > operator is greater than the value on the right side or a constant, the comparison produces a True. Otherwise, the comparison renders False. This operation can be illustrated as follows:

Practical Learning: Finding Out Whether a Value is Greater Than Another

1. Change the document as follows:
```print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Payroll Preparation")
print("-------------------------------------------------------")
print("Enter the following pieces of information")
print("-------------------------------------------------------")
print("Employee Information")
first_name : str= input("First Name:    ")
last_name : str  = input("Last Name:     ")
h_sal : float = float(input("Hourly Salary: "))
print("-------------------------------------------------------")
print("Time worked")
print("-------------------------------------------------------")
mon : float = float(input("Monday:        "))
tue : float = float(input("Tuesday:       "))
wed : float = float(input("Wednesday:     "))
thu : float = float(input("Thursday:      "))
fri : float = float(input("Friday:        "))

time_worked : float = mon + tue + wed + thu + fri

reg_time : float = time_worked
overtime : float = 0.00
over_pay : float = 0.00
reg_pay  : float = h_sal * time_worked

if time_worked > 40.00:
reg_time = 40.00
reg_pay  = h_sal * 40.00
overtime = time_worked - 40.00
over_pay = h_sal * 1.50  * overtime

net_pay : float = reg_pay + over_pay

print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+")
print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Payroll Evaluation")
print("=======================================================")
print("Employee Information")
print("-------------------------------------------------------")
print(f"Full Name:     {first_name} {last_name}")
print(f"Hourly Salary: {h_sal:5.2f}")
print("=======================================================")
print("Work Preparation")
print('--------+---------+-----------+----------+-------------')
print(" Monday | Tuesday | Wednesday | Thursday | Friday")
print('--------+---------+-----------+----------+-------------')
print(f" {mon:5.2f}{tue:8.2f}{wed:12.2f}{thu:12.2f}{fri:10.2f}")
print("=======================================================")
print("\t\t\t\tPay Summary")
print("-------------------------------------------------------")
print("\t\t\t\tTime\tPay")
print("-------------------------------------------------------")
print(f"\t\tRegular:\t{reg_time:5.2f}\t{reg_pay:6.2f}")
print("-------------------------------------------------------")
print(f"\t\tOvertime:\t{overtime:5.2f}\t{over_pay:6.2f}")
print("=======================================================")
print(f"\t\t\tNet Pay:\t{net_pay:6.2f}")
print("=======================================================")```
2. To execute the project, press Ctrl + F5
3. When requested, type the values like in the first example of the previous section and press Enter each time:
```FUN DEPARTMENT STORE
=======================================================
Payroll Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Employee Information
First Name:    Michael
Last Name:     Carlock
Hourly Salary: 28.25
-------------------------------------------------------
Time worked
-------------------------------------------------------
Monday:        7
Tuesday:       8
Wednesday:     6.5
Thursday:      8.5
Friday:        6.5
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Payroll Evaluation
=======================================================
Employee Information
-------------------------------------------------------
Full Name:     Michael Carlock
Hourly Salary: 28.25
=======================================================
Work Preparation
--------+---------+-----------+----------+-------------
Monday | Tuesday | Wednesday | Thursday | Friday
--------+---------+-----------+----------+-------------
7.00    8.00        6.50        8.50      6.50
=======================================================
Pay Summary
-------------------------------------------------------
Time    Pay
-------------------------------------------------------
Regular:        36.50   1031.12
-------------------------------------------------------
Overtime:        0.00     0.00
=======================================================
Net Pay:        1031.12
=======================================================
Press any key to continue . . .```
5. Press Ctrl + F5 to execute again
6. Type the values as in the second example of the previous section and press Enter after each value:
```FUN DEPARTMENT STORE
=======================================================
Payroll Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Employee Information
First Name:    Catherine
Last Name:     Busbey
Hourly Salary: 24.37
-------------------------------------------------------
Time worked
-------------------------------------------------------
Monday:        9.5
Tuesday:       8
Wednesday:     10.5
Thursday:      9
Friday:        10.5
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Payroll Evaluation
=======================================================
Employee Information
-------------------------------------------------------
Full Name:     Catherine Busbey
Hourly Salary: 24.37
=======================================================
Work Preparation
--------+---------+-----------+----------+-------------
Monday | Tuesday | Wednesday | Thursday | Friday
--------+---------+-----------+----------+-------------
9.50    8.00       10.50        9.00     10.50
=======================================================
Pay Summary
-------------------------------------------------------
Time    Pay
-------------------------------------------------------
Regular:        40.00   974.80
-------------------------------------------------------
Overtime:        7.50   274.16
=======================================================
Net Pay:        1248.96
=======================================================
Press any key to continue . . .```

Equalizing an Operator

Logical Difference

We already know that the == operator is used to find out if two values are the same. The opposite is to find out whether two values are different. The operator to do this is !=. It can be illustrated as follows:

A typical Boolean expression involves two operands separated by a logical operator. Both operands must be of the same type. These rules apply to the logical difference. It can be used on numbers, strings, etc. If both operands are different, the operation produces a True result. If they are the exact same, the operation produces False.

The != operator can be used the same way as the equality operator (==) as long as you keep in mind that != is the opposite of ==.

Less Than Or Equal To: <=

The Equality (==) and the Less Than (<) operations can be combined to compare two values. This allows you to know if two values are the same or if the first value is lower than the second value. The operator used is <= and its syntax is:

`value1 <= value2`

The <= operation performs a comparison as any of the last two. If both value1 and value2 hold the same value, the result is True. If the left operand, in this case value1, holds a value lower than the second operand, in this case value2, the result is still True. The <= operation can be illustrated as follows:

Here is an example that uses the <= operator:

```original_price = 124.50
discount_rate = 35.00 # %
number_of_days_in_store = 75

if number_of_days_in_store <= 45:
discount_rate = 25.00

discount_amount = original_price * discount_rate / 100.00
marked_price    = original_price - discount_amount

print("Fun Department Store")
print('----------------------------------')
print("Original Price: ", original_price)
print("Days in Store:  ", number_of_days_in_store)
print("Discount Rate:  ", discount_rate)
print("Discount Amount:", discount_amount)
print("Marked Price:   ", marked_price)
print("==================================")

number_of_days_in_store = 22

if number_of_days_in_store <= 45:
discount_rate = 25.00

discount_amount = original_price * discount_rate / 100.00
marked_price = original_price - discount_amount

print("Fun Department Store")
print('---------------------------------')
print("Original Price: ", original_price)
print("Days in Store:  ", number_of_days_in_store)
print("Discount Rate:  ", discount_rate)
print("Discount Amount:", discount_amount)
print("Marked Price:   ", marked_price)
print("==================================")```

This would produce:

```The object is null.
=======================================
Microwave Oven
---------------------------------------
Make and Model: Farberware FMO12AHTBSG
Capacity:       1.2 cubic-foot
Price:          108.65
=======================================
The object is null.
=======================================
Press any key to continue . . .```

Practical Learning: Comparing for a Lesser Value

1. Change the document as follows:
```print("FUN DEPARTMENT STORE")
print("=======================================================")
print("Payroll Preparation")
print("-------------------------------------------------------")
print("Enter the following pieces of information")
print("-------------------------------------------------------")
print("Employee Information")
first_name : str= input("First Name:    ")
last_name : str  = input("Last Name:     ")
h_sal : float = float(input("Hourly Salary: "))
print("-------------------------------------------------------")
print("Time worked")
print("-------------------------------------------------------")
mon : float = float(input("Monday:        "))
tue : float = float(input("Tuesday:       "))
wed : float = float(input("Wednesday:     "))
thu : float = float(input("Thursday:      "))
fri : float = float(input("Friday:        "))

time_worked : float = mon + tue + wed + thu + fri

reg_time : float = 40.00
reg_pay  : float = h_sal * 40.00
overtime : float = time_worked - 40.00
over_pay : float = h_sal  *  1.50  * overtime

if time_worked <= 40.00:
reg_time = time_worked
overtime = 0.00
over_pay = 0.00
reg_pay  = h_sal * time_worked

net_pay : float = reg_pay + over_pay

print("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+")
print(" --==-- FUN DEPARTMENT STORE --==--")
print("=======================================================")
print("Payroll Evaluation")
print("=======================================================")
print("Employee Information")
print("-------------------------------------------------------")
print(f"Full Name:     {first_name} {last_name}")
print(f"Hourly Salary: {h_sal:5.2f}")
print("=======================================================")
print("Work Preparation")
print('--------+---------+-----------+----------+-------------')
print(" Monday | Tuesday | Wednesday | Thursday | Friday")
print('--------+---------+-----------+----------+-------------')
print(f" {mon:5.2f}{tue:8.2f}{wed:12.2f}{thu:12.2f}{fri:10.2f}")
print("=======================================================")
print("\t\t\t\tPay Summary")
print("-------------------------------------------------------")
print("\t\t\t\tTime\tPay")
print("-------------------------------------------------------")
print(f"\t\tRegular:\t{reg_time:5.2f}\t{reg_pay:6.2f}")
print("-------------------------------------------------------")
print(f"\t\tOvertime:\t{overtime:5.2f}\t{over_pay:6.2f}")
print("=======================================================")
print(f"\t\t\tNet Pay:\t{net_pay:6.2f}")
print("=======================================================")```
2. To execute, press Ctrl + F5
3. When requested, type the values like in the first example of the previous section and press Enter each time:
```FUN DEPARTMENT STORE
=======================================================
Payroll Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Employee Information
First Name:    Michael
Last Name:     Carlock
Hourly Salary: 28.25
-------------------------------------------------------
Time worked
-------------------------------------------------------
Monday:        7
Tuesday:       8
Wednesday:     6.5
Thursday:      8.5
Friday:        6.5
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Payroll Evaluation
=======================================================
Employee Information
-------------------------------------------------------
Full Name:     Michael Carlock
Hourly Salary: 28.25
=======================================================
Work Preparation
--------+---------+-----------+----------+-------------
Monday | Tuesday | Wednesday | Thursday | Friday
--------+---------+-----------+----------+-------------
7.00    8.00        6.50        8.50      6.50
=======================================================
Pay Summary
-------------------------------------------------------
Time    Pay
-------------------------------------------------------
Regular:        36.50   1031.12
-------------------------------------------------------
Overtime:        0.00     0.00
=======================================================
Net Pay:        1031.12
=======================================================
Press any key to continue . . .```
5. Press Ctrl + F5 to execute again
6. Type the values as in the second example of the previous section and press Enter after each value:
```FUN DEPARTMENT STORE
=======================================================
Payroll Preparation
-------------------------------------------------------
Enter the following pieces of information
-------------------------------------------------------
Employee Information
First Name:    Catherine
Last Name:     Busbey
Hourly Salary: 24.37
-------------------------------------------------------
Time worked
-------------------------------------------------------
Monday:        9.5
Tuesday:       8
Wednesday:     10.5
Thursday:      9
Friday:        10.5
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
FUN DEPARTMENT STORE
=======================================================
Payroll Evaluation
=======================================================
Employee Information
-------------------------------------------------------
Full Name:     Catherine Busbey
Hourly Salary: 24.37
=======================================================
Work Preparation
--------+---------+-----------+----------+-------------
Monday | Tuesday | Wednesday | Thursday | Friday
--------+---------+-----------+----------+-------------
9.50    8.00       10.50        9.00     10.50
=======================================================
Pay Summary
-------------------------------------------------------
Time    Pay
-------------------------------------------------------
Regular:        40.00   974.80
-------------------------------------------------------
Overtime:        7.50   274.16
=======================================================
Net Pay:        1248.96
=======================================================
Press any key to continue . . .```
8. Click inside the document, press Ctrl + A to select everything, then type the following code:
```print("===================================================================")
print("Machine Depreciation Evaluation - Straight-Line Method")
print("===================================================================")

estimated_life : int   = 0
machine_cost   : float = 0
salvage_value  : float = 0

print("Enter the values to evaluation the depreciation of the machine")
machine_cost   = float(input("Machine Cost:   "))
salvage_value  = float(input("Salvage Value:  "))
estimated_life = float(input("Estimated Life: "))

depreciation_rate   = 100 / estimated_life
yearly_depreciation = (machine_cost - salvage_value) / estimated_life

book_value_year0  = machine_cost
book_value_year1  = machine_cost - (yearly_depreciation *  1)
book_value_year2  = machine_cost - (yearly_depreciation *  2)
book_value_year3  = machine_cost - (yearly_depreciation *  3)
book_value_year4  = machine_cost - (yearly_depreciation *  4)
book_value_year5  = machine_cost - (yearly_depreciation *  5)
book_value_year6  = machine_cost - (yearly_depreciation *  6)
book_value_year7  = machine_cost - (yearly_depreciation *  7)
book_value_year8  = machine_cost - (yearly_depreciation *  8)
book_value_year9  = machine_cost - (yearly_depreciation *  9)
book_value_year10 = machine_cost - (yearly_depreciation * 10)

accumulated_depreciation1  = yearly_depreciation *  1
accumulated_depreciation2  = yearly_depreciation *  2
accumulated_depreciation3  = yearly_depreciation *  3
accumulated_depreciation4  = yearly_depreciation *  4
accumulated_depreciation5  = yearly_depreciation *  5
accumulated_depreciation6  = yearly_depreciation *  6
accumulated_depreciation7  = yearly_depreciation *  7
accumulated_depreciation8  = yearly_depreciation *  8
accumulated_depreciation9  = yearly_depreciation *  9
accumulated_depreciation10 = yearly_depreciation * 10

print("===================================================================")
print("Machine Depreciation Evaluation - Straight-Line Method")
print("===================================================================")
print(F"Machine Cost:\t\t{machine_cost:6.0f}")
print("-------------------------------------------------------------------")
print(F"Salvage Calue:\t\t{salvage_value:6.0f}")
print("-------------------------------------------------------------------")
print(F"Estimated Life:\t\t{estimated_life:6.0f} years")
print("===================================================================")
print(F"Depreciation Rate:\t{depreciation_rate:6.0f} %")
print("-------------------------------------------------------------------")
print(F"Yearly Depreciation:\t{yearly_depreciation:6.0f}/year")
print("-------------------------------------------------------------------")
print(F"Monthly Depreciation:\t{(yearly_depreciation / 12):6.0f}/month")
print("=====+=====================+============+==========================")
print("Year | Yearly Depreciation | Book Value | Accumulated Depreciation")
print("-----+---------------------+------------+--------------------------")
print(F" 0   |\t\t           |{book_value_year0:10.2f}  |")
print("-----+---------------------+------------+--------------------------")

print(F" 1   |\t{yearly_depreciation:12.2f}       |{book_value_year1:10.2f}  |\t{accumulated_depreciation1:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 2   |\t{yearly_depreciation:12.2f}       |{book_value_year2:10.2f}  |\t{accumulated_depreciation2:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 3   |\t{yearly_depreciation:12.2f}       |{book_value_year3:10.2f}  |\t{accumulated_depreciation3:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 4   |\t{yearly_depreciation:12.2f}       |{book_value_year4:10.2f}  |\t{accumulated_depreciation4:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 5   |\t{yearly_depreciation:12.2f}       |{book_value_year5:10.2f}  |\t{accumulated_depreciation5:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 6   |\t{yearly_depreciation:12.2f}       |{book_value_year6:10.2f}  |\t{accumulated_depreciation6:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 7   |\t{yearly_depreciation:12.2f}       |{book_value_year7:10.2f}  |\t{accumulated_depreciation7:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 8   |\t{yearly_depreciation:12.2f}       |{book_value_year8:10.2f}  |\t{accumulated_depreciation8:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F" 9   |\t{yearly_depreciation:12.2f}       |{book_value_year9:10.2f}  |\t{accumulated_depreciation9:10.2f}")
print("-----+---------------------+------------+--------------------------")
print(F"10   |\t{yearly_depreciation:12.2f}       |{book_value_year10:10.2f}  |\t{accumulated_depreciation10:10.2f}")```
10. For the Machine Cost, type 8568.95 and press Enter
11. For the Salvage Value, type 550 and press Enter
12. For the Estimated Life, type 5 and press Enter
```===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Enter the values to evaluation the depreciation of the machine
Machine Cost:   8568.95
Salvage Value:  550
Estimated Life: 5
===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Machine Cost:             8569
-------------------------------------------------------------------
Salvage Calue:             550
-------------------------------------------------------------------
Estimated Life:              5 years
===================================================================
Depreciation Rate:          20 %
-------------------------------------------------------------------
Yearly Depreciation:      1604/year
-------------------------------------------------------------------
Monthly Depreciation:      134/month
=====+=====================+============+==========================
Year | Yearly Depreciation | Book Value | Accumulated Depreciation
-----+---------------------+------------+--------------------------
0   |                     |   8568.95  |
-----+---------------------+------------+--------------------------
1   |       1603.79       |   6965.16  |          1603.79
-----+---------------------+------------+--------------------------
2   |       1603.79       |   5361.37  |          3207.58
-----+---------------------+------------+--------------------------
3   |       1603.79       |   3757.58  |          4811.37
-----+---------------------+------------+--------------------------
4   |       1603.79       |   2153.79  |          6415.16
-----+---------------------+------------+--------------------------
5   |       1603.79       |    550.00  |          8018.95
-----+---------------------+------------+--------------------------
6   |       1603.79       |  -1053.79  |          9622.74
-----+---------------------+------------+--------------------------
7   |       1603.79       |  -2657.58  |         11226.53
-----+---------------------+------------+--------------------------
8   |       1603.79       |  -4261.37  |         12830.32
-----+---------------------+------------+--------------------------
9   |       1603.79       |  -5865.16  |         14434.11
-----+---------------------+------------+--------------------------
10   |       1603.79       |  -7468.95  |         16037.90
Press any key to continue . . .```
15. For the Machine Cost, type 15888.65 and press Enter
16. For the Salvage Value, type 1250 and press Enter
17. For the Estimated Life, type 10 and press Enter
```===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Enter the values to evaluation the depreciation of the machine
Machine Cost:   15888.65
Salvage Value:  1250
Estimated Life: 10
===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Machine Cost:            15889
-------------------------------------------------------------------
Salvage Calue:            1250
-------------------------------------------------------------------
Estimated Life:             10 years
===================================================================
Depreciation Rate:          10 %
-------------------------------------------------------------------
Yearly Depreciation:      1464/year
-------------------------------------------------------------------
Monthly Depreciation:      122/month
=====+=====================+============+==========================
Year | Yearly Depreciation | Book Value | Accumulated Depreciation
-----+---------------------+------------+--------------------------
0   |                     |  15888.65  |
-----+---------------------+------------+--------------------------
1   |       1463.87       |  14424.78  |          1463.87
-----+---------------------+------------+--------------------------
2   |       1463.87       |  12960.92  |          2927.73
-----+---------------------+------------+--------------------------
3   |       1463.87       |  11497.06  |          4391.60
-----+---------------------+------------+--------------------------
4   |       1463.87       |  10033.19  |          5855.46
-----+---------------------+------------+--------------------------
5   |       1463.87       |   8569.33  |          7319.32
-----+---------------------+------------+--------------------------
6   |       1463.87       |   7105.46  |          8783.19
-----+---------------------+------------+--------------------------
7   |       1463.87       |   5641.59  |         10247.06
-----+---------------------+------------+--------------------------
8   |       1463.87       |   4177.73  |         11710.92
-----+---------------------+------------+--------------------------
9   |       1463.87       |   2713.86  |         13174.78
-----+---------------------+------------+--------------------------
10   |       1463.87       |   1250.00  |         14638.65
Press any key to continue . . .```

A Value Greater Than or Equal to Another: >=

The greater than or the equality operators can be combined to produce an operator as follows: >=. This is the "greater than or equal to" operator. The formula it follows is:

`Value1 >= Value2`

The comparison is performed on both operands: Value1 and Value2:

• If the value of Value1 and that of Value2 are the same, the comparison produces a True value
• If the value of the left operand is greater than that of the right operand, the comparison produces True also
• If the value of the left operand is strictly less than the value of the right operand, the comparison produces a False result

This operation can be illustrated as follows:

Here is an example that uses the >= operator:

```consumption = 0.74
price_per_CCF = 0.00

if consumption >= 0.50:
price_per_CCF = 35.00

monthly_charges = consumption * price_per_CCF

print("Gas Utility Company")
print('---------------------------------')
print("Gas Consumption: ", consumption)
print("Price Per CCF:   ", price_per_CCF)
print("Monthly Charges: ", monthly_charges)
print("==================================")```

This would produce:

```Gas Utility Company
---------------------------------
Gas Consumption:  0.74
Price Per CCF:    35.0
Monthly Charges:  25.9
==================================
Press any key to continue . . .```

Practical Learning: Comparing for a Lesser Value

1. Change the document as follows:
```print("===================================================================")
print("Machine Depreciation Evaluation - Straight-Line Method")
print("===================================================================")

estimated_life : int   = 0
machine_cost   : float = 0
salvage_value  : float = 0

print("Enter the values to evaluation the depreciation of the machine")
machine_cost   = float(input("Machine Cost:   "))
salvage_value  = float(input("Salvage Value:  "))
estimated_life = float(input("Estimated Life: "))

depreciation_rate   = 100 / estimated_life
yearly_depreciation = (machine_cost - salvage_value) / estimated_life

book_value_year0  = machine_cost
book_value_year1  = machine_cost - (yearly_depreciation *  1)
book_value_year2  = machine_cost - (yearly_depreciation *  2)
book_value_year3  = machine_cost - (yearly_depreciation *  3)
book_value_year4  = machine_cost - (yearly_depreciation *  4)
book_value_year5  = machine_cost - (yearly_depreciation *  5)
book_value_year6  = machine_cost - (yearly_depreciation *  6)
book_value_year7  = machine_cost - (yearly_depreciation *  7)
book_value_year8  = machine_cost - (yearly_depreciation *  8)
book_value_year9  = machine_cost - (yearly_depreciation *  9)
book_value_year10 = machine_cost - (yearly_depreciation * 10)

accumulated_depreciation1  = yearly_depreciation *  1
accumulated_depreciation2  = yearly_depreciation *  2
accumulated_depreciation3  = yearly_depreciation *  3
accumulated_depreciation4  = yearly_depreciation *  4
accumulated_depreciation5  = yearly_depreciation *  5
accumulated_depreciation6  = yearly_depreciation *  6
accumulated_depreciation7  = yearly_depreciation *  7
accumulated_depreciation8  = yearly_depreciation *  8
accumulated_depreciation9  = yearly_depreciation *  9
accumulated_depreciation10 = yearly_depreciation * 10

print("===================================================================")
print("Machine Depreciation Evaluation - Straight-Line Method")
print("===================================================================")
print(F"Machine Cost:\t\t{machine_cost:6.0f}")
print("-------------------------------------------------------------------")
print(F"Salvage Calue:\t\t{salvage_value:6.0f}")
print("-------------------------------------------------------------------")
print(F"Estimated Life:\t\t{estimated_life:6.0f} years")
print("===================================================================")
print(F"Depreciation Rate:\t{depreciation_rate:6.0f} %")
print("-------------------------------------------------------------------")
print(F"Yearly Depreciation:\t{yearly_depreciation:6.0f}/year")
print("-------------------------------------------------------------------")
print(F"Monthly Depreciation:\t{(yearly_depreciation / 12):6.0f}/month")
print("=====+=====================+============+==========================")
print("Year | Yearly Depreciation | Book Value | Accumulated Depreciation")
print("-----+---------------------+------------+--------------------------")
print(F" 0   |\t\t           |{book_value_year0:10.2f}  |")
print("-----+---------------------+------------+--------------------------")

if book_value_year1 >= 0:
print(F" 1   |\t{yearly_depreciation:12.2f}       |{book_value_year1:10.2f}  |\t{accumulated_depreciation1:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year2 >= 0:
print(F" 2   |\t{yearly_depreciation:12.2f}       |{book_value_year2:10.2f}  |\t{accumulated_depreciation2:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year3 >= 0:
print(F" 3   |\t{yearly_depreciation:12.2f}       |{book_value_year3:10.2f}  |\t{accumulated_depreciation3:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year4 >= 0:
print(F" 4   |\t{yearly_depreciation:12.2f}       |{book_value_year4:10.2f}  |\t{accumulated_depreciation4:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year5 >= 0:
print(F" 5   |\t{yearly_depreciation:12.2f}       |{book_value_year5:10.2f}  |\t{accumulated_depreciation5:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year6 >= 0:
print(F" 6   |\t{yearly_depreciation:12.2f}       |{book_value_year6:10.2f}  |\t{accumulated_depreciation6:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year7 >= 0:
print(F" 7   |\t{yearly_depreciation:12.2f}       |{book_value_year7:10.2f}  |\t{accumulated_depreciation7:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year8 >= 0:
print(F" 8   |\t{yearly_depreciation:12.2f}       |{book_value_year8:10.2f}  |\t{accumulated_depreciation8:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year9 >= 0:
print(F" 9   |\t{yearly_depreciation:12.2f}       |{book_value_year9:10.2f}  |\t{accumulated_depreciation9:10.2f}")
print("-----+---------------------+------------+--------------------------")
if book_value_year10 >= 0:
print(F"10   |\t{yearly_depreciation:12.2f}       |{book_value_year10:10.2f}  |\t{accumulated_depreciation10:10.2f}")```
3. For the Machine Cost, type 8568.95 and press Enter
4. For the Salvage Value, type 550 and press Enter
5. For the Estimated Life, type 5 and press Enter
```===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Enter the values to evaluation the depreciation of the machine
Machine Cost:   8568.95
Salvage Value:  550
Estimated Life: 5
===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Machine Cost:             8569
-------------------------------------------------------------------
Salvage Calue:             550
-------------------------------------------------------------------
Estimated Life:              5 years
===================================================================
Depreciation Rate:          20 %
-------------------------------------------------------------------
Yearly Depreciation:      1604/year
-------------------------------------------------------------------
Monthly Depreciation:      134/month
=====+=====================+============+==========================
Year | Yearly Depreciation | Book Value | Accumulated Depreciation
-----+---------------------+------------+--------------------------
0   |                     |   8568.95  |
-----+---------------------+------------+--------------------------
1   |       1603.79       |   6965.16  |          1603.79
-----+---------------------+------------+--------------------------
2   |       1603.79       |   5361.37  |          3207.58
-----+---------------------+------------+--------------------------
3   |       1603.79       |   3757.58  |          4811.37
-----+---------------------+------------+--------------------------
4   |       1603.79       |   2153.79  |          6415.16
-----+---------------------+------------+--------------------------
5   |       1603.79       |    550.00  |          8018.95
-----+---------------------+------------+--------------------------
Press any key to continue . . .```
8. For the Machine Cost, type 15888.65 and press Enter
9. For the Salvage Value, type 1250 and press Enter
10. For the Estimated Life, type 10 and press Enter
```===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Enter the values to evaluation the depreciation of the machine
Machine Cost:   15888.65
Salvage Value:  1250
Estimated Life: 10
===================================================================
Machine Depreciation Evaluation - Straight-Line Method
===================================================================
Machine Cost:            15889
-------------------------------------------------------------------
Salvage Calue:            1250
-------------------------------------------------------------------
Estimated Life:             10 years
===================================================================
Depreciation Rate:          10 %
-------------------------------------------------------------------
Yearly Depreciation:      1464/year
-------------------------------------------------------------------
Monthly Depreciation:      122/month
=====+=====================+============+==========================
Year | Yearly Depreciation | Book Value | Accumulated Depreciation
-----+---------------------+------------+--------------------------
0   |                     |  15888.65  |
-----+---------------------+------------+--------------------------
1   |       1463.87       |  14424.78  |          1463.87
-----+---------------------+------------+--------------------------
2   |       1463.87       |  12960.92  |          2927.73
-----+---------------------+------------+--------------------------
3   |       1463.87       |  11497.06  |          4391.60
-----+---------------------+------------+--------------------------
4   |       1463.87       |  10033.19  |          5855.46
-----+---------------------+------------+--------------------------
5   |       1463.87       |   8569.33  |          7319.32
-----+---------------------+------------+--------------------------
6   |       1463.87       |   7105.46  |          8783.19
-----+---------------------+------------+--------------------------
7   |       1463.87       |   5641.59  |         10247.06
-----+---------------------+------------+--------------------------
8   |       1463.87       |   4177.73  |         11710.92
-----+---------------------+------------+--------------------------
9   |       1463.87       |   2713.86  |         13174.78
-----+---------------------+------------+--------------------------
10   |       1463.87       |   1250.00  |         14638.65
Press any key to continue . . .```