为了实现您所描述的功能,我们需要编写一个程序,该程序可以处理客户姓名列表和对应的评分列表,然后计算平均评分、统计优质客户人数,并打印优质客户的姓名。下面是一个简单的Python程序示例来实现这些功能: ```python # 假设客户姓名和评分是预先定义的列表 customer_names = ["tom", "jerry", "marry", "peter", "tony", "jack", "susan", "ross"] customer_scores = [88, 70, 63, 92, 78, 82, 76, 66] # 确保姓名和评分列表长度相同 assert len(customer_names) == len(customer_scores), "姓名和评分列表长度不一致" # 计算客户平均评分 def calculate_average_score(scores): return sum(scores) / len(scores) # 统计优质客户人数 def count_premium_customers(scores, threshold=75): return sum(1 for score in scores if score > threshold) # 打印优质客户姓名 def print_premium_customers(names, scores, threshold=75): for name, score in zip(names, scores): if score > threshold: print(name) # 调用函数并输出结果 average_score = calculate_average_score(customer_scores) premium_count = count_premium_customers(customer_scores) print_premium_customers(customer_names, customer_scores) # 打印平均评分和优质客户人数 print(f"客户平均评分: {average_score:.2f}") print(f"优质客户人数: {premium_count}") ``` 此程序首先定义了客户姓名和评分的列表,然后通过`calculate_average_score`函数计算平均评分,通过`count_premium_customers`函数统计优质客户人数,并使用`print_premium_customers`函数打印优质客户的姓名。程序输出平均评分和优质客户的人数。 此代码段假设客户姓名和评分列表已经存在,并且它们的长度相同。在实际应用中,您可能需要从数据库或其他数据源中获取这些数据。对于大型数据集,您可能需要考虑性能优化,比如使用数据库查询来直接计算平均值和优质客户数。 [2024-05-14 15:57:47 | AI写代码神器 | 500点数解答]