"""
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__":
"""
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)
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"
# 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:
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}")
-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.
"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
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__":
item, qty = arg.split(":")
inventory[item] = int(qty)
except ValueError:
+ print(f"Error parsing varg {arg}, skipping...")
continue
if not inventory:
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
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.
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}")
# 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
# 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))}")
"legend",
]
- print("=== Game Analytics Dashboard ===")
+ print("=== Game Analytics Dashboard ===\n")
print("=== List Comprehension Examples ===")
# High scorers (>2000)
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}")
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)}")
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