diff --git a/system_check.py b/system_check.py index 6c19688..50f9a84 100644 --- a/system_check.py +++ b/system_check.py @@ -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] +print(get_departure_airport("FL-JO234-JNB-CPT-2023")) + + def check_baggage_allowance(ticket_string: str): """ @@ -35,27 +38,44 @@ def check_baggage_allowance(ticket_string: str): - If starts with 'FL': return "First Class - 60kg" - For any other code: return "Standard - 0kg" """ - # TODO: Write your code here - pass + # # TODO: Write your code here + # pass + 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" +print(check_baggage_allowance("FL-JO234-JNB-CPT-2023")) + + def validate_flight_number(ticket_string: str): """ QUESTION 3 ---------------------------------------- Extract the Flight Number (the part between 1st and 2nd hyphen, e.g., "JO234"). - + "FL-JO234-JNB-CPT-2023" + Logic: - If the number portion (e.g., 234) is Even, return "Valid - Northbound" - If the number portion is Odd, return "Valid - Southbound" - If the numeric part cannot be converted to a number, return "Invalid Flight" """ - # TODO: Write your code here - pass + # # 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" +print(validate_flight_number("FL-JOABC-JNB-CPT")) -# ========================================== -# SECTION B: ALGORITHMIC LOGIC (MATH) -# ========================================== def is_leap_year(year: int): """ @@ -71,38 +91,54 @@ def is_leap_year(year: int): Return True or False (Boolean). """ - # TODO: Write your code here - pass - + # # TODO: Write your code here + # pass + 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 + +print(is_leap_year(2020)) -# ========================================== -# SECTION C: COMPLEX LOGIC & TDD -# ========================================== +# # ========================================== +# # SECTION C: COMPLEX LOGIC & TDD +# # ========================================== -def reactor_status(temp: int, radiation: int): - """ - QUESTION 5 (THE LOGIC MONITOR) - ---------------------------------------- - Analyze a nuclear reactor's status based on Temperature (C) and Radiation (Sv). +# def reactor_status(temp: int, radiation: int): +# """ +# QUESTION 5 (THE LOGIC MONITOR) +# ---------------------------------------- +# Analyze a nuclear reactor's status based on Temperature (C) and Radiation (Sv). - TODO: Using TDD, implement tests for the below functionality. - Create `test_reactor.py` with class `TestReactor`. +# TODO: Using TDD, implement tests for the below functionality. +# Create `test_reactor.py` with class `TestReactor`. - Logic Tree: - 1. NEGATIVE CHECKS (Invalid Sensors): - - If temp OR radiation is less than 0: return "Sensor Error" +# Logic Tree: +# 1. NEGATIVE CHECKS (Invalid Sensors): +# - If temp OR radiation is less than 0: return "Sensor Error" - 2. CRITICAL (Meltdown imminent): - - If temp > 2000 OR radiation > 500: return "CRITICAL" +# 2. CRITICAL (Meltdown imminent): +# - If temp > 2000 OR radiation > 500: return "CRITICAL" - 3. WARNING (Unstable): - - If temp is between 1000 and 2000 (inclusive) AND radiation > 100: return "WARNING" +# 3. WARNING (Unstable): +# - If temp is between 1000 and 2000 (inclusive) AND radiation > 100: return "WARNING" - 4. MAINTENANCE (Low output): - - If temp < 500: return "Maintenance Mode" +# 4. MAINTENANCE (Low output): +# - If temp < 500: return "Maintenance Mode" - 5. NORMAL: - - For all other cases: return "Normal Operation" - """ - # TODO: Write your code here - pass +# 5. NORMAL: +# - For all other cases: return "Normal Operation" +# """ +# # TODO: Write your code here +# pass