-
Notifications
You must be signed in to change notification settings - Fork 15
Ntsika Khanya Gajula #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,77 +3,97 @@ | |||||||||||||||||||||||||||||||||||||||
| # ========================================== | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def get_departure_airport(ticket_string: str): | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| QUESTION 1 | ||||||||||||||||||||||||||||||||||||||||
| ---------------------------------------- | ||||||||||||||||||||||||||||||||||||||||
| Extract the Departure Airport Code from the ticket string. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Format of ticket_string: "FL-JO234-JNB-CPT-2023" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Logic: | ||||||||||||||||||||||||||||||||||||||||
| - The code is situated between the second and third hyphen (-). | ||||||||||||||||||||||||||||||||||||||||
| - In the example "FL-JO234-JNB-CPT-2023", the departure is "JNB". | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Harder Twist: You cannot use fixed indices (e.g., [10:13]) because the | ||||||||||||||||||||||||||||||||||||||||
| Flight Number (JO234) can vary in length. You must find it relative to the hyphens. | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| QUESTION 1 | ||||||||||||||||||||||||||||||||||||||||
| ---------------------------------------- | ||||||||||||||||||||||||||||||||||||||||
| Extract the Departure Airport Code from the ticket string. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Format of ticket_string: "FL-JO234-JNB-CPT-2023" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Logic: | ||||||||||||||||||||||||||||||||||||||||
| - The code is situated between the second and third hyphen (-). | ||||||||||||||||||||||||||||||||||||||||
| - In the example "FL-JO234-JNB-CPT-2023", the departure is "JNB". | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Harder Twist: You cannot use fixed indices (e.g., [10:13]) because the | ||||||||||||||||||||||||||||||||||||||||
| Flight Number (JO234) can vary in length. You must find it relative to the hyphens. | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||
| fl_class, fl_num, DepAirCode, ArrAirCode, fl_year = ticket_string.split("-") | ||||||||||||||||||||||||||||||||||||||||
| print(f"The Departure Airport: {DepAirCode}") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def check_baggage_allowance(ticket_string: str): | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| QUESTION 2 | ||||||||||||||||||||||||||||||||||||||||
| ---------------------------------------- | ||||||||||||||||||||||||||||||||||||||||
| Determine the baggage allowance based on the Flight Class. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Format: The first two letters of the string indicate the class. | ||||||||||||||||||||||||||||||||||||||||
| Example: "FL-..." starts with "FL". | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Logic: | ||||||||||||||||||||||||||||||||||||||||
| - If starts with 'EC': return "Economy - 20kg" | ||||||||||||||||||||||||||||||||||||||||
| - If starts with 'BS': return "Business - 40kg" | ||||||||||||||||||||||||||||||||||||||||
| - If starts with 'FL': return "First Class - 60kg" | ||||||||||||||||||||||||||||||||||||||||
| - For any other code: return "Standard - 0kg" | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| QUESTION 2 | ||||||||||||||||||||||||||||||||||||||||
| ---------------------------------------- | ||||||||||||||||||||||||||||||||||||||||
| Determine the baggage allowance based on the Flight Class. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Format: The first two letters of the string indicate the class. | ||||||||||||||||||||||||||||||||||||||||
| Example: "FL-..." starts with "FL". | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Logic: | ||||||||||||||||||||||||||||||||||||||||
| - If starts with 'EC': return "Economy - 20kg" | ||||||||||||||||||||||||||||||||||||||||
| - If starts with 'BS': return "Business - 40kg" | ||||||||||||||||||||||||||||||||||||||||
| - If starts with 'FL': return "First Class - 60kg" | ||||||||||||||||||||||||||||||||||||||||
| - For any other code: return "Standard - 0kg" | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||
| fl_class, fl_num, DepAirCode, ArrAirCode, fl_year = ticket_string.split("-") | ||||||||||||||||||||||||||||||||||||||||
| print(f"The Flight Class: {fl_class}") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
42
|
||||||||||||||||||||||||||||||||||||||||
| print(f"The Flight Class: {fl_class}") | |
| if fl_class.startswith('EC'): | |
| return "Economy - 20kg" | |
| elif fl_class.startswith('BS'): | |
| return "Business - 40kg" | |
| elif fl_class.startswith('FL'): | |
| return "First Class - 60kg" | |
| else: | |
| return "Standard - 0kg" |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isdigit is a method and must be called with parentheses: i.isdigit(). Without the parentheses, this always evaluates to True (since the method object is truthy), causing all characters to be appended to the list.
| if i.isdigit: | |
| if i.isdigit(): |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should return "Valid - Northbound", "Valid - Southbound", or "Invalid Flight" based on whether the numeric portion of the flight number is even, odd, or invalid. However, the current implementation only extracts and prints the digits without performing the required logic or returning any value.
| print(f"The Flight Number: {fl_num}") | |
| flight_digits = [] | |
| for i in fl_num: | |
| if i.isdigit: | |
| flight_digits.append(i) | |
| print(flight_digits) | |
| # Extract digits from flight number | |
| flight_digits = ''.join([i for i in fl_num if i.isdigit()]) | |
| if not flight_digits: | |
| return "Invalid Flight" | |
| try: | |
| num = int(flight_digits) | |
| except ValueError: | |
| return "Invalid Flight" | |
| if num % 2 == 0: | |
| return "Valid - Northbound" | |
| else: | |
| return "Valid - Southbound" |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the leap year rules, if the year is divisible by 100, it should proceed to check if it's divisible by 400. However, this implementation returns False when divisible by 100 but not by 400, which is correct, but the logic flow is incorrect. If the year is divisible by 100, it should NOT return True immediately (line 92 is unreachable). The correct logic should check divisibility by 400 and return True/False accordingly, not return True for any year divisible by 100.
| if year % 4 == 0: | |
| pass | |
| else: | |
| return False | |
| if year % 100 == 0: | |
| pass | |
| else: | |
| return False | |
| if year % 400 == 0: | |
| return True | |
| else: | |
| return False | |
| if year % 4 != 0: | |
| return False | |
| if year % 100 != 0: | |
| return True | |
| if year % 400 == 0: | |
| return True | |
| return False |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition 1000 < temp > 2000 is incorrect. This checks if 1000 < temp AND temp > 2000, which can never be true (temp can't be both greater than 1000 and greater than 2000 means less than 2000). The correct condition should be 1000 <= temp <= 2000 and radiation > 100 to check if temp is between 1000 and 2000 (inclusive) as per the requirements.
| elif 1000 < temp > 2000 and radiation > 100: | |
| elif 1000 <= temp <= 2000 and radiation > 100: |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These function calls and test statements should be removed from the module-level code or placed inside a if __name__ == "__main__": block. When this module is imported by test files, these statements will execute automatically, which is undesirable and can interfere with testing.
| get_departure_airport("FL-JO234-JNB-CPT-2023") | |
| check_baggage_allowance("FL-JO234-JNB-CPT-2023") | |
| validate_flight_number("FL-JO234-JNB-CPT-2023") | |
| print(is_leap_year(2000)) | |
| print(is_leap_year(2001)) | |
| print(is_leap_year(2002)) | |
| print(is_leap_year(2016)) | |
| if __name__ == "__main__": | |
| get_departure_airport("FL-JO234-JNB-CPT-2023") | |
| check_baggage_allowance("FL-JO234-JNB-CPT-2023") | |
| validate_flight_number("FL-JO234-JNB-CPT-2023") | |
| print(is_leap_year(2000)) | |
| print(is_leap_year(2001)) | |
| print(is_leap_year(2002)) | |
| print(is_leap_year(2016)) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from system_check import reactor_status | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from system_check import reactor_status |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(1500, 115), "WARNING")
| self.assertEqual((15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual((2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual((1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual((475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual((250, 35), "Normal Operation") | |
| self.assertEqual(reactor_status(15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual(reactor_status(2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual(reactor_status(1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual(reactor_status(475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual(reactor_status(250, 35), "Normal Operation") |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(250, 35), "Normal Operation")
| self.assertEqual((15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual((2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual((1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual((475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual((250, 35), "Normal Operation") | |
| self.assertEqual(reactor_status(15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual(reactor_status(2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual(reactor_status(1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual(reactor_status(475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual(reactor_status(250, 35), "Normal Operation") |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(475, 56), "Maintenance Mode")
| self.assertEqual((15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual((2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual((1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual((475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual((250, 35), "Normal Operation") | |
| self.assertEqual(reactor_status(15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual(reactor_status(2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual(reactor_status(1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual(reactor_status(475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual(reactor_status(250, 35), "Normal Operation") |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertEqual method expects the actual value as the first argument and the expected value as the second argument. This test is currently calling assertEqual with a tuple as the first argument instead of calling the reactor_status function. It should be: self.assertEqual(reactor_status(15, -5), "Sensor Error")
| self.assertEqual((15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual((2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual((1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual((475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual((250, 35), "Normal Operation") | |
| self.assertEqual(reactor_status(15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual(reactor_status(2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual(reactor_status(1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual(reactor_status(475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual(reactor_status(250, 35), "Normal Operation") |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertEqual method is not being called correctly. It should be: self.assertEqual(reactor_status(2100, 459), "CRITICAL")
| self.assertEqual((15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual((2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual((1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual((475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual((250, 35), "Normal Operation") | |
| self.assertEqual(reactor_status(15, -5), "Sensor Error") | |
| def test_critical(self): | |
| self.assertEqual(reactor_status(2100, 459), "CRITICAL") | |
| def test_warning(self): | |
| self.assertEqual(reactor_status(1500, 115), "WARNING") | |
| def test_maintenance(self): | |
| self.assertEqual(reactor_status(475, 56), "Maintenance Mode") | |
| def test_normal_operation(self): | |
| self.assertEqual(reactor_status(250, 35), "Normal Operation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should return the departure airport code, but it only prints the value. Add
return DepAirCodeafter the print statement.