]> Untitled Git - axy/ft/python04.git/commitdiff
Add solutions for Python exercises 0-4
authorAxy <gilliardmarthey.axel@gmail.com>
Mon, 19 Jan 2026 15:27:53 +0000 (16:27 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Mon, 19 Jan 2026 15:27:53 +0000 (16:27 +0100)
ex0/ft_ancient_text.py [new file with mode: 0644]
ex1/ft_archive_creation.py [new file with mode: 0644]
ex2/ft_stream_management.py [new file with mode: 0644]
ex3/ft_vault_security.py [new file with mode: 0644]
ex4/ft_crisis_response.py [new file with mode: 0644]

diff --git a/ex0/ft_ancient_text.py b/ex0/ft_ancient_text.py
new file mode 100644 (file)
index 0000000..27abeac
--- /dev/null
@@ -0,0 +1,19 @@
+def main():
+    print("=== CYBER ARCHIVES - DATA RECOVERY SYSTEM ===")
+    filename = "ancient_fragment.txt"
+    print(f"Accessing Storage Vault: {filename}")
+
+    try:
+        f = open(filename, "r")
+        print("Connection established...")
+        print("RECOVERED DATA:")
+        content = f.read()
+        print(content)
+        f.close()
+        print("Data recovery complete. Storage unit disconnected.")
+    except FileNotFoundError:
+        print("ERROR: Storage vault not found. Run data generator first.")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/ex1/ft_archive_creation.py b/ex1/ft_archive_creation.py
new file mode 100644 (file)
index 0000000..1098501
--- /dev/null
@@ -0,0 +1,30 @@
+def main():
+    print("=== CYBER ARCHIVES - PRESERVATION SYSTEM ===")
+    filename = "new_discovery.txt"
+    print(f"Initializing new storage unit: {filename}")
+
+    try:
+        f = open(filename, "w")
+        print("Storage unit created successfully...")
+        print("Inscribing preservation data...")
+
+        entries = [
+            "[ENTRY 001] New quantum algorithm discovered",
+            "[ENTRY 002] Efficiency increased by 347%",
+            "[ENTRY 003] Archived by Data Archivist trainee",
+        ]
+
+        for entry in entries:
+            f.write(entry + "\n")
+            print(entry)
+
+        f.close()
+        print("Data inscription complete. Storage unit sealed.")
+        print(f"Archive '{filename}' ready for long-term preservation.")
+
+    except Exception as e:
+        print(f"Error: {e}")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/ex2/ft_stream_management.py b/ex2/ft_stream_management.py
new file mode 100644 (file)
index 0000000..cbe51d6
--- /dev/null
@@ -0,0 +1,22 @@
+import sys
+
+
+def main():
+    print("=== CYBER ARCHIVES - COMMUNICATION SYSTEM ===")
+
+    arch_id = input("Input Stream active. Enter archivist ID: ")
+    status = input("Input Stream active. Enter status report: ")
+
+    print(
+        f"[STANDARD] Archive status from {arch_id}: {status}", file=sys.stdout
+    )
+    print(
+        "[ALERT] System diagnostic: Communication channels verified",
+        file=sys.stderr,
+    )
+    print("[STANDARD] Data transmission complete", file=sys.stdout)
+    print("Three-channel communication test successful.")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/ex3/ft_vault_security.py b/ex3/ft_vault_security.py
new file mode 100644 (file)
index 0000000..edc3ce8
--- /dev/null
@@ -0,0 +1,27 @@
+def main():
+    print("=== CYBER ARCHIVES - VAULT SECURITY SYSTEM ===")
+    print("Initiating secure vault access...")
+    print("Vault connection established with failsafe protocols")
+
+    print("SECURE EXTRACTION:")
+    try:
+        with open("classified_data.txt", "r") as f:
+            print(f.read())
+    except FileNotFoundError:
+        print("Error: classified_data.txt not found")
+
+    print("SECURE PRESERVATION:")
+    try:
+        with open("security_protocols.txt", "w") as f:
+            data = "[CLASSIFIED] New security protocols archived"
+            f.write(data)
+            print(data)
+    except Exception as e:
+        print(f"Error: {e}")
+
+    print("Vault automatically sealed upon completion")
+    print("All vault operations completed with maximum security.")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/ex4/ft_crisis_response.py b/ex4/ft_crisis_response.py
new file mode 100644 (file)
index 0000000..d4a40b6
--- /dev/null
@@ -0,0 +1,30 @@
+def crisis_handler(filename, context):
+    print(f"{context}: Attempting access to '{filename}'...")
+    try:
+        with open(filename, "r") as f:
+            content = f.read().strip()
+            print(f"SUCCESS: Archive recovered - '{content}'")
+            print("STATUS: Normal operations resumed")
+    except FileNotFoundError:
+        print("RESPONSE: Archive not found in storage matrix")
+        print("STATUS: Crisis handled, system stable")
+    except PermissionError:
+        print("RESPONSE: Security protocols deny access")
+        print("STATUS: Crisis handled, security maintained")
+    except Exception as e:
+        print(f"RESPONSE: Unexpected error: {e}")
+        print("STATUS: Crisis handled, system stable")
+
+
+def main():
+    print("=== CYBER ARCHIVES - CRISIS RESPONSE SYSTEM ===")
+
+    crisis_handler("lost_archive.txt", "CRISIS ALERT")
+    crisis_handler("classified_vault.txt", "CRISIS ALERT")
+    crisis_handler("standard_archive.txt", "ROUTINE ACCESS")
+
+    print("All crisis scenarios handled successfully. Archives secure.")
+
+
+if __name__ == "__main__":
+    main()