aisha#9
Conversation
There was a problem hiding this comment.
Pull request overview
This PR appears to be a homework/exercise submission that implements several functions for a flight ticket system and date validation. The changes include implementations for parsing flight ticket data, validating flight numbers, and checking leap years. However, the implementations contain multiple critical bugs and logic errors.
Key Changes
- Implementation of
get_departure_airport,check_baggage_allowance, andvalidate_flight_numberfunctions for flight ticket parsing - Implementation of
is_leap_yearfunction for date validation - Commenting out of the
reactor_statusfunction and section headers
Comments suppressed due to low confidence (5)
system_check.py:72
- This statement is unreachable.
if ticket_string[7]!=2 or 4 or 6 or 8 or 0:
system_check.py:22
- Print statement may execute during import.
print(get_departure_airport("FL-JO234-JNB-CPT-2023"))
system_check.py:51
- Print statement may execute during import.
print(check_baggage_allowance("FL-JO234-JNB-CPT-2023"))
system_check.py:76
- Print statement may execute during import.
print(validate_flight_number("FL-JOABC-JNB-CPT"))
system_check.py:112
- Print statement may execute during import.
print(is_leap_year(2020))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pass | ||
| # # TODO: Write your code here | ||
| # pass | ||
| return ticket_string[9] +ticket_string[10] +ticket_string[11] |
There was a problem hiding this comment.
The string concatenation with + operator is inefficient and hard to read. Consider using string slicing instead: return ticket_string[9:12]. This is more concise and follows Python best practices for extracting substrings.
| return ticket_string[9] +ticket_string[10] +ticket_string[11] | |
| return ticket_string.split('-')[2] |
| # # TODO: Write your code here | ||
| # pass | ||
| return ticket_string[9] +ticket_string[10] +ticket_string[11] | ||
| print(get_departure_airport("FL-JO234-JNB-CPT-2023")) |
There was a problem hiding this comment.
Debug print statement should be removed before committing code. This appears to be leftover from testing.
| print(get_departure_airport("FL-JO234-JNB-CPT-2023")) |
| if ticket_string[0]+ticket_string[1]=='EC': | ||
| return "Economy - 20kg" | ||
| elif ticket_string[0]+ticket_string[1]=='BS': | ||
| return "Business - 40kg" | ||
| elif ticket_string[0]+ticket_string[1]=='FL': | ||
| return "First Class - 60kg" | ||
| else: | ||
| return "Standard - 0kg" |
There was a problem hiding this comment.
String concatenation with + operator is inefficient and hard to read. Consider using string slicing: ticket_string[:2] or the split method as mentioned in the function requirements.
| print(check_baggage_allowance("FL-JO234-JNB-CPT-2023")) | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Debug print statement should be removed before committing code. This appears to be leftover from testing.
| print(check_baggage_allowance("FL-JO234-JNB-CPT-2023")) |
| # # TODO: Write your code here | ||
| # pass | ||
|
|
||
| if ticket_string[7]==2 or 4 or 6 or 8 or 0: | ||
| return "Valid - Northbound" | ||
| if ticket_string[7]!=2 or 4 or 6 or 8 or 0: | ||
| return "Valid - Southbound" | ||
| if not ticket_string.isdigit(): | ||
| return "Invalid Flight" |
There was a problem hiding this comment.
This condition has the same logical error as line 70. Additionally, this logic is flawed because it doesn't properly extract and validate the numeric portion of the flight number. The function should: 1) split the string to get the flight number segment, 2) extract only the numeric portion, 3) check if it's a valid number, and 4) check if it's even or odd.
| # # TODO: Write your code here | |
| # pass | |
| if ticket_string[7]==2 or 4 or 6 or 8 or 0: | |
| return "Valid - Northbound" | |
| if ticket_string[7]!=2 or 4 or 6 or 8 or 0: | |
| return "Valid - Southbound" | |
| if not ticket_string.isdigit(): | |
| return "Invalid Flight" | |
| import re | |
| # Split the ticket string by hyphens | |
| parts = ticket_string.split('-') | |
| if len(parts) < 2: | |
| return "Invalid Flight" | |
| flight_segment = parts[1] | |
| # Extract numeric portion from flight_segment | |
| match = re.search(r'(\d+)', flight_segment) | |
| if not match: | |
| return "Invalid Flight" | |
| number_str = match.group(1) | |
| try: | |
| number = int(number_str) | |
| except ValueError: | |
| return "Invalid Flight" | |
| if number % 2 == 0: | |
| return "Valid - Northbound" | |
| else: | |
| return "Valid - Southbound" |
| pass | ||
| # # TODO: Write your code here | ||
| # pass | ||
| return ticket_string[9] +ticket_string[10] +ticket_string[11] |
There was a problem hiding this comment.
This implementation uses hardcoded indices which violates the stated requirement: "You cannot use fixed indices (e.g., [10:13]) because the Flight Number (JO234) can vary in length." The correct approach is to find the departure airport by splitting on hyphens: return ticket_string.split('-')[2].
| return ticket_string[9] +ticket_string[10] +ticket_string[11] | |
| return ticket_string.split('-')[2] |
| return "Valid - Southbound" | ||
| if not ticket_string.isdigit(): | ||
| return "Invalid Flight" | ||
| print(validate_flight_number("FL-JOABC-JNB-CPT")) |
There was a problem hiding this comment.
Debug print statement should be removed before committing code. This appears to be leftover from testing.
| print(validate_flight_number("FL-JOABC-JNB-CPT")) |
| year=12 | ||
| a=4 | ||
| b=100 | ||
| c=400 | ||
|
|
||
| if year%a==0: | ||
| if year%b==0: | ||
| if year%c==0: | ||
| return True | ||
| else: | ||
| return False | ||
| else: | ||
| return True | ||
| else: | ||
| return True |
There was a problem hiding this comment.
These variable names (a, b, c) are not descriptive. Use meaningful names like divisor_four, divisor_hundred, and divisor_four_hundred, or better yet, use the numeric literals directly in the conditions for clarity.
| year=12 | |
| a=4 | |
| b=100 | |
| c=400 | |
| if year%a==0: | |
| if year%b==0: | |
| if year%c==0: | |
| return True | |
| else: | |
| return False | |
| else: | |
| return True | |
| else: | |
| return True | |
| # Use the function argument 'year' directly | |
| if year % 4 == 0: | |
| if year % 100 == 0: | |
| if year % 400 == 0: | |
| return True | |
| else: | |
| return False | |
| else: | |
| return True | |
| else: | |
| return False |
| ---------------------------------------- | ||
| Extract the Flight Number (the part between 1st and 2nd hyphen, e.g., "JO234"). | ||
|
|
||
| "FL-JO234-JNB-CPT-2023" |
There was a problem hiding this comment.
Inconsistent formatting: Added extra indentation (8 spaces) before the example string. This line should be aligned with the other lines in the docstring using 4 spaces.
| "FL-JO234-JNB-CPT-2023" | |
| "FL-JO234-JNB-CPT-2023" |
| # - For all other cases: return "Normal Operation" | ||
| # """ | ||
| # # TODO: Write your code here | ||
| # pass |
There was a problem hiding this comment.
This comment appears to contain commented-out code.
| # pass |
No description provided.