课程开源地址:课程进度列表 - 聪明办法学 Python 第二版
章节结构:
直接写题了。。。。注意验证后提交,不然不算分。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
def is_prime(n):
if n < 2:
return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
def check_lucky_word(word):
# 计算每个字母的出现次数
letter_counts = [word.count(letter) for letter in set(word)]
# 找到出现次数最多和最少的字母的次数
max_count = max(letter_counts)
min_count = min(letter_counts)
# 计算差值
diff = max_count - min_count
# 判断差值是否为质数
if is_prime(diff):
return "Lucky Word", diff
else:
return "No Answer", 0
# 从输入中获取单词
word = input()
# 调用函数检查单词是否是Lucky Word并打印结果
result, diff = check_lucky_word(word)
print(result)
print(diff)
def is_prime(n):
if n < 2:
return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
def goldbach_conjecture(n):
results = []
for i in range(4, n+1, 2):
for j in range(2, i//2 + 1):
if is_prime(j) and is_prime(i-j):
results.append((i, j, i-j))
break
return results
# 从输入中获取偶数N
N = int(input())
# 调用函数验证哥德巴赫猜想并打印结果
results = goldbach_conjecture(N)
for result in results:
even_num, prime1, prime2 = result
print(f"{even_num}={prime1}+{prime2}")
def check_whale_schedule(schedule):
max_unhappiness = 0
unhappiest_day = 0
for day, (school_hours, mom_hours) in enumerate(schedule, start=1):
total_hours = school_hours + mom_hours
# 计算不高兴程度
unhappiness = max(0, total_hours - 8)
# 更新最大不高兴程度和对应的天数
if unhappiness > max_unhappiness:
max_unhappiness = unhappiness
unhappiest_day = day
return unhappiest_day
# 从输入中获取每天的上课时间和安排时间
schedule = []
for _ in range(7):
school_hours, mom_hours = map(int, input().split())
schedule.append((school_hours, mom_hours))
# 调用函数检查小鲸鱼的日程安排并打印结果
result = check_whale_schedule(schedule)
print(result)
def calculate_swimming_time(start_hour, start_minute, end_hour, end_minute):
# 将开始时间和结束时间转换为分钟数
start_time = start_hour * 60 + start_minute
end_time = end_hour * 60 + end_minute
# 计算游泳时间
total_time = end_time - start_time
# 将总时间转换为小时和分钟
hours = total_time // 60
minutes = total_time % 60
return hours, minutes
# 从输入中获取开始时间和结束时间
start_hour, start_minute, end_hour, end_minute = map(int, input().split())
# 调用函数计算游泳时间并打印结果
result = calculate_swimming_time(start_hour, start_minute, end_hour, end_minute)
print(result[0], result[1])
def calculate_score(scores):
weights = [0.2, 0.3, 0.5]
total_score = sum(score * weight for score, weight in zip(scores, weights))
return int(total_score)
# 从输入中获取三个成绩
scores = list(map(int, input().split()))
# 调用函数计算最终成绩并打印结果
result = calculate_score(scores)
print(result)
最后的竞赛撒花,通过半个月的复习,加深了对python的印象,不知道当时约定好一起学习python的小伙伴还在一起学习,每次都会写在笔记里的,希望大家坚持下去,不仅是分享这份开源,更是分享自己的成长,抽时间出来和大家学习讨论还是挺有意义的,希望以后还会有这个心气去完成后续课程的学习,另外鼓励更多的小伙伴加入到DataWhale的开源当中去,构建开源生态,最后借此机会,祝DataWhale越来越好,五周年生日快乐。。。。