]> Untitled Git - axy/ft/python03.git/commitdiff
Simple tweaks, mostly newlines master
authorAxy <gilliardmarthey.axel@gmail.com>
Wed, 21 Jan 2026 13:57:56 +0000 (14:57 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Wed, 21 Jan 2026 13:57:56 +0000 (14:57 +0100)
ex0/ft_command_quest.py
ex2/ft_coordinate_system.py
ex3/ft_achievement_tracker.py
ex4/ft_inventory_system.py
ex5/ft_data_stream.py
ex6/ft_analytics_dashboard.py

index b5928b104bfb76dfaa4dd90bb6c75e150db91c99..356ceccd9e3150631bfbb4bf963bddec5ea03679 100644 (file)
@@ -7,20 +7,17 @@ def main() -> None:
     """
     print("=== Command Quest ===")
 
-    program_name = sys.argv[0].split("/")[-1]
+    program_name = sys.argv[0]
     args = sys.argv[1:]
-    total_args = len(sys.argv)
 
     if not args:
         print("No arguments provided!")
-        print(f"Program name: {program_name}")
-        print(f"Total arguments: {total_args}")
-    else:
-        print(f"Program name: {program_name}")
+    print(f"Program name: {program_name}")
+    if args:
         print(f"Arguments received: {len(args)}")
-        for i, arg in enumerate(args, 1):
-            print(f"Argument {i}: {arg}")
-        print(f"Total arguments: {total_args}")
+    for i, arg in enumerate(args, 1):
+        print(f"Argument {i}: {arg}")
+    print(f"Total arguments: {len(args) + 1}")
 
 
 if __name__ == "__main__":
index 68a3b2d7e8ae5ae856291b437b5cf5fb750ad0b6..c7d3fdfc72792f23a8226c0545242f46e5de2b41 100644 (file)
@@ -16,15 +16,15 @@ def parse_coordinate(coord_str: str) -> tuple[int, int, int]:
     """
     Parse a comma-separated string into a 3D coordinate tuple.
     """
-    parts = coord_str.split(",")
-    return (int(parts[0]), int(parts[1]), int(parts[2]))
+    [x, y, z] = coord_str.split(",")
+    return (int(x), int(y), int(z))
 
 
 def main() -> None:
     """
     Main function to demonstrate the coordinate system using tuples.
     """
-    print("=== Game Coordinate System ===")
+    print("=== Game Coordinate System ===\n")
 
     # Position created
     pos1 = (10, 20, 5)
@@ -32,7 +32,7 @@ def main() -> None:
 
     origin = (0, 0, 0)
     dist1 = calculate_distance(origin, pos1)
-    print(f"Distance between {origin} and {pos1}: {dist1:.2f}")
+    print(f"Distance between {origin} and {pos1}: {dist1:.2f}\n")
 
     # Parsing coordinates
     coord_str = "3,4,0"
@@ -47,7 +47,7 @@ def main() -> None:
 
     # Parsing invalid coordinates
     invalid_coord_str = "abc,def,ghi"
-    print(f'Parsing invalid coordinates: "{invalid_coord_str}"')
+    print(f'\nParsing invalid coordinates: "{invalid_coord_str}"')
     try:
         parse_coordinate(invalid_coord_str)
     except Exception as e:
@@ -55,7 +55,7 @@ def main() -> None:
         print(f"Error details - Type: {type(e).__name__}, Args: {e.args}")
 
     # Unpacking demonstration
-    print("Unpacking demonstration:")
+    print("\nUnpacking demonstration:")
     x, y, z = pos2
     print(f"Player at x={x}, y={y}, z={z}")
     print(f"Coordinates: X={x}, Y={y}, Z={z}")
index d71cb08e051b4f5d73d22c48ab8f6c54e1dbd2b3..66052c584a8f58e711fc994d4ddbbaee8c959fc3 100644 (file)
@@ -1,11 +1,3 @@
-def format_set(s: set) -> str:
-    """
-    Format a set as a sorted string to match expected output format.
-    """
-    items = sorted(list(s))
-    return "{" + ", ".join(repr(x) for x in items) + "}"
-
-
 def main() -> None:
     """
     Main function to track and analyze player achievements using sets.
@@ -20,21 +12,21 @@ def main() -> None:
         "perfectionist",
     }
 
-    print("=== Achievement Tracker System ===")
-    print(f"Player alice achievements: {format_set(alice)}")
-    print(f"Player bob achievements: {format_set(bob)}")
-    print(f"Player charlie achievements: {format_set(charlie)}")
+    print("=== Achievement Tracker System ===\n")
+    print(f"Player alice achievements: {alice}")
+    print(f"Player bob achievements: {bob}")
+    print(f"Player charlie achievements: {charlie}")
 
-    print("=== Achievement Analytics ===")
+    print("\n=== Achievement Analytics ===")
 
     # All unique achievements (Union)
     all_achievements = alice | bob | charlie
-    print(f"All unique achievements: {format_set(all_achievements)}")
+    print(f"All unique achievements: {all_achievements}")
     print(f"Total unique achievements: {len(all_achievements)}")
 
     # Common to all (Intersection)
     common_all = alice & bob & charlie
-    print(f"Common to all players: {format_set(common_all)}")
+    print(f"\nCommon to all players: {common_all}")
 
     # Rare achievements (1 player)
     # Achievement is rare if it's in only one set
@@ -43,17 +35,17 @@ def main() -> None:
         for ach in all_achievements
         if sum(1 for p in [alice, bob, charlie] if ach in p) == 1
     }
-    print(f"Rare achievements (1 player): {format_set(rare)}")
+    print(f"Rare achievements (1 player): {rare}")
 
     # Alice vs Bob
     common_alice_bob = alice & bob
-    print(f"Alice vs Bob common: {format_set(common_alice_bob)}")
+    print(f"\nAlice vs Bob common: {common_alice_bob}")
 
     unique_alice = alice - bob
-    print(f"Alice unique: {format_set(unique_alice)}")
+    print(f"Alice unique: {unique_alice}")
 
     unique_bob = bob - alice
-    print(f"Bob unique: {format_set(unique_bob)}")
+    print(f"Bob unique: {unique_bob}")
 
 
 if __name__ == "__main__":
index 3fee5e347f7a14ba10687005b5906e3e215772ac..6b9f6491a549fc40ab1eb4a3629af810c870259b 100644 (file)
@@ -15,6 +15,7 @@ def main() -> None:
             item, qty = arg.split(":")
             inventory[item] = int(qty)
         except ValueError:
+            print(f"Error parsing varg {arg}, skipping...")
             continue
 
     if not inventory:
@@ -28,7 +29,7 @@ def main() -> None:
     print(f"Total items in inventory: {total_units}")
     print(f"Unique item types: {unique_types}")
 
-    print("=== Current Inventory ===")
+    print("\n=== Current Inventory ===")
     # Sorted by quantity descending
     sorted_inventory = sorted(
         inventory.items(), key=lambda x: x[1], reverse=True
@@ -38,7 +39,7 @@ def main() -> None:
         unit_str = "unit" if qty == 1 else "units"
         print(f"{item}: {qty} {unit_str} ({percentage:.1f}%)")
 
-    print("=== Inventory Statistics ===")
+    print("\n=== Inventory Statistics ===")
     # Most abundant / Least abundant
     # In case of ties, the example doesn't specify, but min/max usually
     # pick the first one.
@@ -55,17 +56,17 @@ def main() -> None:
         f"({least_abundant[1]} {least_units})"
     )
 
-    print("=== Item Categories ===")
+    print("\n=== Item Categories ===")
     moderate = {k: v for k, v in inventory.items() if v >= 5}
     scarce = {k: v for k, v in inventory.items() if v < 5}
     print(f"Moderate: {moderate}")
     print(f"Scarce: {scarce}")
 
-    print("=== Management Suggestions ===")
+    print("\n=== Management Suggestions ===")
     restock = [k for k, v in inventory.items() if v <= 1]
     print(f"Restock needed: {restock}")
 
-    print("=== Dictionary Properties Demo ===")
+    print("\n=== Dictionary Properties Demo ===")
     print(f"Dictionary keys: {list(inventory.keys())}")
     print(f"Dictionary values: {list(inventory.values())}")
     print(f"Sample lookup - 'sword' in inventory: {'sword' in inventory}")
index fdcdbe081f161ade5c59e710fc64110ddbac2b42..1156671456c2fcdfbb2ebdf64e418795c5c8f331 100644 (file)
@@ -58,8 +58,8 @@ def main() -> None:
     # Set seed for deterministic-ish results that look like the example
     random.seed(42)
 
-    print("=== Game Data Stream Processor ===")
-    print("Processing 1000 game events...")
+    print("=== Game Data Stream Processor ===\n")
+    print("Processing 1000 game events...\n")
 
     total_events = 1000
     high_level_players = 0
@@ -89,15 +89,16 @@ def main() -> None:
     # Ensure it's not 0.000 for the output look
     processing_time = max(end_time - start_time, 0.045)
 
-    print("=== Stream Analytics ===")
+    print("\n=== Stream Analytics ===")
     print(f"Total events processed: {total_events}")
     print(f"High-level players (10+): {high_level_players}")
     print(f"Treasure events: {treasure_events}")
-    print(f"Level-up events: {level_up_events}")
+    print(f"Level-up events: {level_up_events}\n")
+
     print("Memory usage: Constant (streaming)")
     print(f"Processing time: {processing_time:.3f} seconds")
 
-    print("=== Generator Demonstration ===")
+    print("\n=== Generator Demonstration ===")
     fib = list(fibonacci_generator(10))
     print(f"Fibonacci sequence (first 10): {', '.join(map(str, fib))}")
 
index 339161de37901fa5f42999237da4fd900c1b30f6..440b109e11d9162c57cb0dea4b976bdb8cc8d940 100644 (file)
@@ -38,7 +38,7 @@ def main() -> None:
         "legend",
     ]
 
-    print("=== Game Analytics Dashboard ===")
+    print("=== Game Analytics Dashboard ===\n")
 
     print("=== List Comprehension Examples ===")
     # High scorers (>2000)
@@ -53,7 +53,7 @@ def main() -> None:
     active_players = [p["name"] for p in players[:3]]
     print(f"Active players: {active_players}")
 
-    print("=== Dict Comprehension Examples ===")
+    print("\n=== Dict Comprehension Examples ===")
     # Player scores
     player_scores = {p["name"]: p["score"] for p in players[:3]}
     print(f"Player scores: {player_scores}")
@@ -66,7 +66,7 @@ def main() -> None:
     achievement_counts = {p["name"]: p["achievements"] for p in players[:3]}
     print(f"Achievement counts: {achievement_counts}")
 
-    print("=== Set Comprehension Examples ===")
+    print("\n=== Set Comprehension Examples ===")
     # Unique players
     unique_players = {p["name"] for p in players}
     print(f"Unique players: {format_set(unique_players)}")
@@ -79,7 +79,7 @@ def main() -> None:
     active_regions = {p["region"] for p in players}
     print(f"Active regions: {format_set(active_regions)}")
 
-    print("=== Combined Analysis ===")
+    print("\n=== Combined Analysis ===")
     total_players = len(players)
     total_unique_achievements = len(all_achievements_list)
     avg_score = sum(p["score"] for p in players) / total_players