今日进行了python的学习。对于昨天的测试代码进行了分析学习。
R7-1 字典合并
d1 = eval(input()) d2 = eval(input()) for key in d2.keys(): d1[key] = d1.get(key, 0) + d2[key] t = list(d1.items()) t.sort(key=lambda x: ord(x[0]) if type(x[0]) == str else x[0]) out = str(dict(t)).replace(' ', '').replace("'", '"') print(out)
R7-2 python-列表:统计考试成绩
score = list(input().split()) sum = 0 max_score = float(score[0]) min_score = float(score[0]) passed = 0 for i in range(0,len(score)): if float(score[i]) > max_score: max_score = float(score[i]) if float(score[i]) < min_score: min_score = float(score[i]) if float(score[i]) >= 60: passed = passed + 1 sum = sum + float(score[i]) average = sum/len(score) passed_rate = passed/len(score)*100 print("及格率:{:.1f}%".format(passed_rate)) print("平均分:{:.1f}".format(average)) print("最高分:{:.1f}".format(max_score)) print("最低分:{:.1f}".format(min_score))
R7-3 找出一个整数的所有素因子
def sushu(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors n = int(input()) factors = sushu(n) print(','.join(map(str, factors)))
标签:总结,key,factors,每日,float,score,5.17,passed,print From: https://www.cnblogs.com/syhxx/p/17410163.html