Skip to content

Keamogetswe's submission#2

Open
KeaMokoena-codes wants to merge 2 commits into
micanipho:mainfrom
KeaMokoena-codes:main
Open

Keamogetswe's submission#2
KeaMokoena-codes wants to merge 2 commits into
micanipho:mainfrom
KeaMokoena-codes:main

Conversation

@KeaMokoena-codes
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This submission implements solutions for a Python formative assessment covering flight ticket parsing, leap year logic, and a reactor safety monitor with test-driven development.

Key changes:

  • Implemented four core functions in system_check.py: departure airport extraction, baggage allowance checking, flight number validation, and leap year determination
  • Added reactor_status function with conditional logic for nuclear reactor safety monitoring
  • Created test_reactor.py with unit tests for the reactor status function (TDD requirement)

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 12 comments.

File Description
system_check.py Implements all five required functions with string parsing, modulo operations, and conditional logic; includes debug print statements
test_reactor.py Provides unit tests for reactor_status function covering critical, warning, and normal operation scenarios
.vscode/settings.json Configures VS Code to use unittest as the testing framework
pycache/*.pyc Generated bytecode files from Python execution
Comments suppressed due to low confidence (5)

system_check.py:24

  • Print statement may execute during import.
print(get_departure_airport("FL-JO234-JNB-CPT-2023"))

system_check.py:54

  • Print statement may execute during import.
print(check_baggage_allowance("FL-JO234-JNB-CPT-2023"))

system_check.py:78

  • Print statement may execute during import.
print(validate_flight_number("FL-A9-JNB-CPT-2023"))

system_check.py:109

  • Print statement may execute during import.
print(is_leap_year(1900))

system_check.py:152

  • Print statement may execute during import.
print(reactor_status(1500, 200))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread system_check.py
Comment on lines +22 to +23
depature_airport_code = new_string[2]
return depature_airport_code
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in variable name: "depature" should be "departure".

Suggested change
depature_airport_code = new_string[2]
return depature_airport_code
departure_airport_code = new_string[2]
return departure_airport_code

Copilot uses AI. Check for mistakes.
Comment thread system_check.py
new_string = ticket_string.split("-")
depature_airport_code = new_string[2]
return depature_airport_code
print(get_departure_airport("FL-JO234-JNB-CPT-2023"))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be removed from production code. Print statements at the module level can clutter output and are typically only used during development/debugging.

Copilot uses AI. Check for mistakes.
Comment thread system_check.py Outdated
Comment on lines +70 to +77
number_portion = int(flight_number.replace("JO", "").replace("A", ""))
if number_portion % 2 == 0:
return "Valid - Northbound"
if number_portion % 2 != 0:
return "Valid - Southbound"
# I don't know what's wrong with this part of the code, I lost my brain cells!!!
if number_portion.isdigit() == False:
return "Invalid Flight"
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic has a critical flaw. The code attempts to convert to int first (line 70), which will raise a ValueError if the conversion fails. This means lines 76-77 (which check if it's not a digit) are unreachable code - if the string contains non-numeric characters, the function will crash at line 70 before reaching the validation check.

The correct approach is to:

  1. Extract the numeric portion as a string
  2. Check if it's a valid digit using isdigit()
  3. Only then convert to int

For example:

number_str = flight_number.replace("JO", "").replace("A", "")
if not number_str.isdigit():
    return "Invalid Flight"
number_portion = int(number_str)
Suggested change
number_portion = int(flight_number.replace("JO", "").replace("A", ""))
if number_portion % 2 == 0:
return "Valid - Northbound"
if number_portion % 2 != 0:
return "Valid - Southbound"
# I don't know what's wrong with this part of the code, I lost my brain cells!!!
if number_portion.isdigit() == False:
return "Invalid Flight"
number_str = flight_number.replace("JO", "").replace("A", "")
if not number_str.isdigit():
return "Invalid Flight"
number_portion = int(number_str)
if number_portion % 2 == 0:
return "Valid - Northbound"
else:
return "Valid - Southbound"

Copilot uses AI. Check for mistakes.
Comment thread system_check.py Outdated
# I don't know what's wrong with this part of the code, I lost my brain cells!!!
if number_portion.isdigit() == False:
return "Invalid Flight"
print(validate_flight_number("FL-A9-JNB-CPT-2023"))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be removed from production code. Print statements at the module level can clutter output and are typically only used during development/debugging.

Copilot uses AI. Check for mistakes.
Comment thread system_check.py
return True
else:
return False
print(is_leap_year(1900))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be removed from production code. Print statements at the module level can clutter output and are typically only used during development/debugging.

Copilot uses AI. Check for mistakes.
Comment thread system_check.py
number_portion = int(flight_number.replace("JO", "").replace("A", ""))
if number_portion % 2 == 0:
return "Valid - Northbound"
if number_portion % 2 != 0:
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using elif instead of separate if statements for the mutually exclusive northbound/southbound conditions. Since a number can't be both even and odd, using elif improves code clarity.

For example:

if number_portion % 2 == 0:
    return "Valid - Northbound"
else:  # or elif number_portion % 2 != 0:
    return "Valid - Southbound"
Suggested change
if number_portion % 2 != 0:
elif number_portion % 2 != 0:

Copilot uses AI. Check for mistakes.
Comment thread test_reactor.py
import unittest
from system_check import reactor_status

class TestReactor:
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TestReactor class must inherit from unittest.TestCase for the test methods to work properly. Without this inheritance, the test runner won't recognize this as a test class, and methods like self.assertEqual will fail since they are not defined.

Change:

class TestReactor:

To:

class TestReactor(unittest.TestCase):
Suggested change
class TestReactor:
class TestReactor(unittest.TestCase):

Copilot uses AI. Check for mistakes.
Comment thread system_check.py
return "First Class - 60kg"
else:
return "Standard - 0kg"
print(check_baggage_allowance("FL-JO234-JNB-CPT-2023"))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be removed from production code. Print statements at the module level can clutter output and are typically only used during development/debugging.

Copilot uses AI. Check for mistakes.
Comment thread system_check.py
return "Maintenance Mode"
else:
return "Normal Operation"
print(reactor_status(1500, 200))
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be removed from production code. Print statements at the module level can clutter output and are typically only used during development/debugging.

Copilot uses AI. Check for mistakes.
Comment thread system_check.py
Comment on lines +48 to +50
if baggage_allowance == 'BS':
return "Business - 40kg"
if baggage_allowance == 'FL':
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using elif instead of multiple if statements for mutually exclusive conditions. This improves readability and performance by avoiding unnecessary condition checks once a match is found.

For example:

if baggage_allowance == 'EC':
    return "Economy - 20kg"
elif baggage_allowance == 'BS':
    return "Business - 40kg"
elif baggage_allowance == 'FL':
    return "First Class - 60kg"
else:
    return "Standard - 0kg"
Suggested change
if baggage_allowance == 'BS':
return "Business - 40kg"
if baggage_allowance == 'FL':
elif baggage_allowance == 'BS':
return "Business - 40kg"
elif baggage_allowance == 'FL':

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants