-
Notifications
You must be signed in to change notification settings - Fork 15
aisha #9
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?
aisha #9
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ========================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SECTION A: DATA PARSING (FLIGHT TICKET SYSTEM) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ========================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_departure_airport(ticket_string: str): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QUESTION 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -17,8 +16,12 @@ def get_departure_airport(ticket_string: str): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # # TODO: Write your code here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ticket_string[9] +ticket_string[10] +ticket_string[11] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ticket_string[9] +ticket_string[10] +ticket_string[11] | |
| return ticket_string.split('-')[2] |
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.
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] |
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.
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")) |
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.
Inconsistent indentation: the comment has extra leading spaces. The indentation should align with the function body using 4 spaces, not 3 spaces plus 2 extra spaces.
| # # TODO: Write your code here | |
| # pass | |
| # TODO: Write your code here | |
| # pass |
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.
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.
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.
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")) |
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.
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" |
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.
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" |
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.
This condition is logically incorrect. The expression ticket_string[7]==2 or 4 or 6 or 8 or 0 doesn't check if the character equals any of these values. In Python, or 4 is always truthy, making this condition always evaluate to True. The correct approach is: if int(ticket_string[7]) % 2 == 0: to check if the digit is even.
| 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" | |
| # Extract the flight number between the first and second hyphens | |
| parts = ticket_string.split('-') | |
| if len(parts) < 2: | |
| return "Invalid Flight" | |
| flight_number = parts[1] | |
| # Extract the numeric part from the flight number | |
| numeric_part = ''.join(filter(str.isdigit, flight_number)) | |
| if not numeric_part: | |
| return "Invalid Flight" | |
| try: | |
| num = int(numeric_part) | |
| 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.
This check is applied to the entire ticket string rather than just the numeric portion of the flight number. This will always return False since the ticket string contains hyphens and letters. The validation should be applied only to the extracted numeric portion of the flight number.
| # # 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 | |
| # Extract flight number (between first and second hyphen) | |
| parts = ticket_string.split('-') | |
| if len(parts) < 2: | |
| return "Invalid Flight" | |
| flight_number = parts[1] | |
| # Extract numeric portion from flight number | |
| match = re.search(r'(\d+)', flight_number) | |
| if not match: | |
| return "Invalid Flight" | |
| num_str = match.group(1) | |
| try: | |
| num = int(num_str) | |
| 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.
Debug print statement should be removed before committing code. This appears to be leftover from testing.
| print(validate_flight_number("FL-JOABC-JNB-CPT")) |
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 parameter year is immediately overwritten with the hardcoded value 12, making the function always operate on year 12 regardless of input. Remove line 96 to use the actual parameter value.
| year=12 |
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 leap year logic is incorrect. The else branch on line 110 returns True, but it should return False since years not divisible by 4 are not leap years. The correct return value should be False.
| 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.
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 |
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.
Debug print statement should be removed before committing code. This appears to be leftover from testing.
| print(is_leap_year(2020)) |
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.
This comment appears to contain commented-out code.
| # pass |
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.
Inconsistent indentation: the comment has extra leading spaces. The indentation should align with the function body using 4 spaces, not 3 spaces plus 2 extra spaces.