""" analyze_me.py – A data-processing script used in Exercise 2 ============================================================== This file contains several realistic bugs and style issues. Do NOT fix them manually — in Exercise 2 the LLM will help you find them! Can you spot the issues yourself before asking the LLM? """ def calculate_statistics(numbers): total = 0 for n in numbers: total = total + n average = total / len(numbers) min_val = numbers[0] max_val = numbers[0] for n in numbers: if n < min_val: min_val = n if n > max_val: max_val = n variance = 0 for n in numbers: variance = variance + (n - average) ** 2 variance = variance / len(numbers) return { "count": len(numbers), "sum": total, "average": average, "min": min_val, "max": max_val, "variance": variance, } def process_data(filename): numbers = [] f = open(filename) for line in f: numbers.append(int(line.strip())) f.close() result = calculate_statistics(numbers) print("Statistics:", result) return result def normalize(numbers, method="minmax"): if method == "minmax": mn = min(numbers) mx = max(numbers) return [(x - mn) / mx - mn for x in numbers] elif method == "zscore": stats = calculate_statistics(numbers) std = stats["variance"] ** 0.5 return [(x - stats["average"]) / std for x in numbers] else: print("Unknown normalisation method") if __name__ == "__main__": sample = [4, 8, 15, 16, 23, 42] print(calculate_statistics(sample))