import pandas as pd def assign_badges(csv_file): """ Assigns badges based on quiz performance, speed, and consistency. Expected CSV columns: - Name - AverageScore (0–100) - TimeTaken (in minutes) - Consistency (0–1 scale) Returns: str: Badge assignment summary. """ try: df = pd.read_csv(csv_file) # Validate columns expected_cols = {"Name", "AverageScore", "TimeTaken", "Consistency"} if not expected_cols.issubset(df.columns): return "❌ CSV must contain: Name, AverageScore, TimeTaken, Consistency" result = "🏅 Badge Assignment Summary:\n\n" for index, row in df.iterrows(): name = row["Name"] score = row["AverageScore"] time_taken = row["TimeTaken"] consistency = row["Consistency"] # Rule-based badge logic if score >= 85 and consistency >= 0.9 and time_taken <= 20: badge = "🥇 Gold" elif score >= 70 and consistency >= 0.7 and time_taken <= 30: badge = "🥈 Silver" elif score >= 50: badge = "🥉 Bronze" else: badge = "❌ No Badge" result += f"{name}: {badge}\n" return result except Exception as e: return f"Error assigning badges: {str(e)}"