


下面是错误答案,如果正确,纯属巧合
1、代码如下:
n = int(input("请输入一个正整数n:")) sum = 0 for i in range(1, n+1): sum += i**2 print("1~{}之间正整数的平方和为:{}".format(n, sum))
2、代码如下:
nums = [12, 24, 59, 15, 6, 4] total = sum(nums) mean = total/len(nums) print("这组数的和为:{},平均值为:{}".format(total, mean))
3、代码如下:
nums = [14, 22, 50, 74, 81, 99, 100] index = 0 for num in nums: if num % 3 == 0: print("找到了第一个能被3整除的数{},位置为{}。".format(num, index)) break index += 1 else: print("没有找到能被3整除的数。")
4、代码如下:
k = [98, 77, 45, 80, 35, 90, 85, 92, 48, 82, 76] count = 0 total_score = 0 for score in k: if score >= 60: count += 1 total_score += score if count > 0: avg_score = total_score/count print("共有{}人及格,平均成绩为{}。".format(count, avg_score)) else: print("没有及格的人。")