first commit

This commit is contained in:
liligeng111 2025-08-06 02:04:35 +08:00
parent abc6526143
commit 26631f9b48
24 changed files with 1089 additions and 1 deletions

13
Exercise/exercise-1.1.py Normal file
View file

@ -0,0 +1,13 @@
# 计算 12879 * 36521 并打印
# product = ???
# print(product)
# 计算 100 模 32 并打印
# mod = ???
# print(mod)
# 打印Hello\ "World!"
# msg = ???
# print(msg)

8
Exercise/exercise-1.2.py Normal file
View file

@ -0,0 +1,8 @@
import math
# 请输出以下关于圆的周长和面积的计算保留3位小数
radius = 3
pi = math.pi
# 应当输出 当圆的的半径是3时它的周长是18.850他的面积是28.274
print('当圆的的半径是时,它的周长是,他的面积是')

9
Exercise/exercise-2.1.py Normal file
View file

@ -0,0 +1,9 @@
# 请尝试修改list以满足输出
list_a = [0]
list_a += ['Hello'] * 5
list_a += [4, 5] * 3
# 输出[0, 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 4, 5, 4, 5, 4, 5]
print(list_a)

18
Exercise/exercise-2.2.py Normal file
View file

@ -0,0 +1,18 @@
# 我们用如下数组存储一些患者的信息
patient_info = [
["Zhang San", 52, "M"],
["Li Si", 19, "F"],
["Wang Wu", 47, "F"],
]
# 检查后发现,张三的年龄和李四的年龄写反了,请将他们调整过来
# 应当为 19
print(patient_info[0][1])
# 应当为 52
print(patient_info[1][1])

19
Exercise/exercise-2.3.py Normal file
View file

@ -0,0 +1,19 @@
age_dict = {
"Zhang San": 52,
"Li Si": 19,
"Wang Wu": 47
}
# 检查后发现张三的年龄和李四的年龄写反了请将他们调整过来。并添加Zhao Liu年龄为29
# 应当为 19
print(age_dict['Zhang San'])
# 应当为 52
print(age_dict['Li Si'])
# 应当为 29
print(age_dict['Zhao Liu'])

13
Exercise/exercise-3.1.py Normal file
View file

@ -0,0 +1,13 @@
# 请根据用户输入的年龄输出在学校的阶段:
# 0-5 输出 学龄前
# 6-11 输出 小学
# 12-14 输出 初中
# 15-17 输出 高中
# 18-21 输出 大学
# 22-59 输出 打工人
# 60+ 输出 退休了
print('请输入你的年龄:')
age = int(input())
if age < 6:
print('学龄前')

33
Exercise/exercise-4.1.py Normal file
View file

@ -0,0 +1,33 @@
# 我们希望将患者按照信息分别按照性别和年龄分成4个组别分别存储他们的姓名
patient_info = [
["Zhang San", 52, "M"],
["Li Si", 19, "F"],
["Wang Wu", 47, "F"],
["Zhao Liu", 29, "M"],
]
group_M_under_30 = []
group_M_over_30 = []
group_F_under_30 = []
group_F_over_30 = []
for patient in patient_info:
print('new patient:', patient)
# 补充代码使用条件判断将患者分为4组分别存储他们的姓名即可
# 应当为 ["Zhao Liu"]
print(group_M_under_30)
# 应当为 ["Zhang San"]
print(group_M_over_30)
# 应当为 ["Li Si"]
print(group_F_under_30)
# 应当为 ["Wang Wu"]
print(group_F_over_30)

15
Exercise/exercise-4.2.py Normal file
View file

@ -0,0 +1,15 @@
# 给定一组整数,计算他们的和并输出等式
magic_number_list = [4, 8, 15, 16, 23, 42]
sum = 0
expression = ''
for index in range(len(magic_number_list)):
print(index)
# 应输出4 + 8 + 15 + 16 + 23 + 42 = 108
print(expression)

14
Exercise/exercise-4.3.py Normal file
View file

@ -0,0 +1,14 @@
import random
# 我们来写一个猜数字的小游戏
# 生成一个随机的1-100整数作为答案
answer = random.randint(1, 100)
game_over = False
count = 0
while not game_over:
print(f"你已经猜了{count}次,请输入下一次猜测")
count += 1
guess = int(input())
print(f"你的猜测是{guess}")
# 如果猜对了,输出“猜对了”并结束游戏。否则输出“猜大了”或者“猜小了”

10
Exercise/exercise-5.1.py Normal file
View file

@ -0,0 +1,10 @@
# 我们来输出100以内的素数
def is_prime(n):
# 检查n是否是素数一个简易的办法是遍历小于n的自然数判断是否有自然数可以整除n
return False
for i in range(100):
# 遍历100以内的自然数检查他们是不是素数并输出其中的素数
result = is_prime(i)

23
Exercise/exercise-5.2.py Normal file
View file

@ -0,0 +1,23 @@
import random
# 概率计算表明23个人中有至少两人生日相同的概率高达50.7%,听起来有些反直觉,我们来通过计算估计这一概率。
def contains_same_birthday(birthdays):
# 修改代码判断birthdays这个list中是否有相同的元素
return True
# 我们进行10000次测试
test_count = 10000
# 有至少两人生日相同的次数
true_count = 0
for i in range(test_count):
birth_days = []
for j in range(23):
birth_days.append(random.randint(1, 365))
# 统计满足条件的测试次数
# 输出测试结果保留4位小数
print('23个人中有至少两人生日相同的概率是:')

8
Exercise/exercise-5.3.py Normal file
View file

@ -0,0 +1,8 @@
# 哥德巴赫猜想Goldbach's conjecture是数论中存在最久的未解问题之一。这个猜想最早出现在1742年普鲁士数学家克里斯蒂安·哥德巴赫与瑞士数学家莱昂哈德·欧拉的通信中。用现代的数学语言哥德巴赫猜想可以陈述为
# 任一大于2的偶数都可表示成两个素数之和
# 验证1000以内偶数是否满足这一猜想并输出每一个结果例如
# 4 = 2 + 2
# 6 = 3 + 3
# 8 = 3 + 5