综合练习(一)
一、选择题
- 某校组织环保知识竞赛,为参加社区级比赛做选手选拔工作,经过多次测试后,有4名同学成为区级参赛选手的候选人,具体情况如下表:
甲 | 乙 | 丙 | 丁 | |
---|---|---|---|---|
平均分 | 90 | 92 | 95 | 95 |
方差 | 36 | 32 | 21 | 33 |
如果从这 4 名同学中选出 1 位参加区级比赛(总体水平高且状态稳定),你会推荐( C
)
(A) 甲 (B) 乙 ( C)丙 (D) 丁
# 1. solution 1 - 不借助第三方库
def select1(candidates):
# 找出平均分最高的同学(可能有多个)
max_mean = max(candidate['mean'] for candidate in candidates.values())
candidates_by_mean = [name for name, info in candidates.items() if info['mean'] == max_mean]
# 在平均分最高的同学中,找出方差最小的(状态最稳定)
min_variance = min(candidates[name]['variance'] for name in candidates_by_mean)
recommend_student = [name for name in candidates_by_mean if candidates[name]['variance']==min_variance][0]
return recommend_student
candidates = {
"甲": {"mean": 90, "variance": 36},
"乙": {"mean": 92, "variance": 32},
"丙": {"mean": 95, "variance": 21},
"丁": {"mean": 95, "variance": 33}
}
best_candidate = select1(candidates)
print(best_candidate)
丙
# 1. solution 2 使用 pandas
import pandas as pd
def select2(candidates):
df_candidates = pd.DataFrame(candidates)
# 计算稳定性指标 (根据当前题目,假定稳定性指标等于均值减去方差)
df_candidates['recommend_metrics'] = df_candidates['mean'] - df_candidates['variance']
best_candidate = df_candidates.loc[df_candidates['recommend_metrics'].idxmax()]['name']
return best_candidate
# 创建一个 DataFrame来存储候选人的数据
candidates = {
'name': ['甲', '乙', '丙', '丁'],
'mean': [90, 92, 95, 95],
'variance': [36, 32, 21, 33]
}
best_candidate = select2(candidates)
print(best_candidate)
丙
-
学习了四边形之后,王老师用如下图所示的方式表示了四边形与特殊的四边形的关系,则图中的 “M” 和 “N” 分别表示( B )
(A) M 表示菱形, N 表示正方形
(B) M 表示正方形, N 表示菱形
© M 表示正方形, N 表示梯形
(D) M 表示菱形, N 表示梯形
definition = {
"Quadrilateral": "由不在同一直线上的四条线段依次首尾相接围成的封闭的平面图形或立体图形叫四边形 。",
"Parallelogram": "两组对边分别平行的四边形叫做平行四边形 。",
"Rectangle": "有一个角是直角的平行四边形叫做矩形,矩形是特殊的平行四边形,它具有平行四边形的所有性质,且四个角都是直角 。",
"Rhombus": "在同一平面内,有一组邻边相等的平行四边形是菱形,菱形是特殊的平行四边形,它具有平行四边形的所有性质,且四条边都相等 。",
"Square": "有一组邻边相等并且有一个角是直角的平行四边形叫做正方形。正方形既是特殊的矩形(有一组邻边相等 ),又是特殊的菱形(有一个角是直角 ),所以正方形是矩形和菱形的公共部分。"
}
for 形状, 定义 in definition.items():
print(f'{形状}: {定义}')
Quadrilateral: 由不在同一直线上的四条线段依次首尾相接围成的封闭的平面图形或立体图形叫四边形 。
Parallelogram: 两组对边分别平行的四边形叫做平行四边形 。
Rectangle: 有一个角是直角的平行四边形叫做矩形,矩形是特殊的平行四边形,它具有平行四边形的所有性质,且四个角都是直角 。
Rhombus: 在同一平面内,有一组邻边相等的平行四边形是菱形,菱形是特殊的平行四边形,它具有平行四边形的所有性质,且四条边都相等 。
Square: 有一组邻边相等并且有一个角是直角的平行四边形叫做正方形。正方形既是特殊的矩形(有一组邻边相等 ),又是特殊的菱形(有一个角是直角 ),所以正方形是矩形和菱形的公共部分。
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
# 创建一个图形和子图
fig, ax = plt.subplots()
# 创建椭圆对象
ellipse1 = Ellipse(xy=(0.5, 0.5), width=0.8, height=0.6, angle=0, facecolor='white', edgecolor="black", linewidth=2, alpha=0.7)
ellipse2 = Ellipse(xy=(0.5,0.46), width=0.6, height=0.48, angle=0, facecolor='white', edgecolor="black", linewidth=2, alpha=0.5)
ellipse3 = Ellipse(xy=(0.43,0.42), width=0.3, height=0.3, angle=0, facecolor='white', edgecolor='black', linewidth=2, alpha=0.5)
ellipse4 = Ellipse(xy=(0.57,0.42), width=0.3, height=0.3, angle=0, facecolor='white', edgecolor='black', linewidth=2, alpha=0.5)
# 将椭圆添加到子图中
ax.add_patch(ellipse1)
ax.add_patch(ellipse2)
ax.add_patch(ellipse3)
ax.add_patch(ellipse4)
# 添加文字
ax.text(0.5, 0.74, '四边形', fontsize=12, ha='center', color='black')
ax.text(0.5, 0.64, '平行四边形', fontsize=12, ha='center', color='black')
ax.text(0.37, 0.4, '矩形', fontsize=12, ha='center', color='black')
ax.text(0.5, 0.42, 'M', fontsize=16, ha='center', color='black')
ax.text(0.62, 0.42, 'N', fontsize=16, ha='center', color='black')
# 设置坐标轴范围
# ax.set_xlim(0, 1)
# ax.set_ylim(0, 1)
ax.axis('off')
# 显示图形
plt.show()
解析: 在这个关系图中,最大的椭圆表示四边形,里面的椭圆表示平行四边形,平行四边形包含矩形和另一种特殊平行四边形(菱形),而矩形和菱形的重叠部分M ,因为正方形既是特殊的矩形又是特殊的菱形,所以M是正方形;N 是和矩形并列的特殊平行四边形,根据定义可知N是菱形 。梯形是只有一组对边平行的四边形,不属于平行四边形,所以C、D选项中涉及梯形的可排除;A选项中M、N 表示错误,也可排除。所以,答案选 (B)。
二、填空题
- 如图,在 △\triangle△ ABC 中,点 D, E分别是 AB, BC 的中点,若 AC = 6, 则 DE 的长为 ____________
根据三角形中位线定理,DE=12AC,已知AC=6,则DE=12×6=3。DE=\frac{1}{2}AC,已知 AC = 6,则 DE=\frac{1}{2}\times6 = 3 。DE=21AC,已知AC=6,则DE=21×6=3。
import matplotlib.pyplot as plt
from shapely.geometry import Point, Polygon
# 设置中文字体
plt.rcParams["font.family"] = ["SimHei"]
# 手动设置坐标
B = (1, 2)
A = (7, 5)
C = (9, 2)
D = ((A[0]+B[0])/2, (A[1]+B[1])/2)
E = ((B[0]+C[0])/2, (B[1]+C[1])/2)
# Polygon 生成三角形并获取 x, y坐标
triangle1 = Polygon([A, B, C])
x1, y1 = triangle1.exterior.xy
triangle2 = Polygon([D,B,E])
x2, y2 = triangle2.exterior.xy
# 绘制三角形
plt.figure(figsize=(8, 6))
plt.plot(x1, y1, 'k-', linewidth=2)
plt.plot(x2, y2, 'k-', linewidth=1)
# 标记
for point, label in zip([A, B, C, D, E], ['A','B','C', 'D', 'E']):
if label == 'E' or label == 'C':
plt.annotate(label, (point[0], point[1]-0.25), fontsize=12)
else:
plt.annotate(label, (point[0], point[1]+0.15), fontsize=12)
# 设置图形属性
# 设置x和y轴刻度等长
plt.axis('equal')
# 关闭坐标轴
plt.axis('off')
# 显示图形
plt.show()
- 一次函数 y=kx+b(k≠0)y = kx+b(k\neq0)y=kx+b(k=0) 的图像如图所示:那么 k ___ 0, b ___0 (填 “>” 或 “<”)
solution:
根据图象走势和与y轴交点判断k、b符号。
判断k的符号:
一次函数y=kx+b(k≠0),当k>0时,函数图象从左到右上升。此图象呈上升趋势,所以k>0一次函数 y = kx + b(k\neq0),当 k\gt0 时,函数图象从左到右上升 。此图象呈上升趋势,所以k\gt0一次函数y=kx+b(k=0),当k>0时,函数图象从左到右上升。此图象呈上升趋势,所以k>0。判断b的符号:b是函数图象与y轴交点的纵坐标,图象与y轴交于负半轴,所以b<0b\lt0b<0。
import matplotlib.pyplot as plt
import numpy as np
# 定义x的取值范围
x = np.linspace(-2, 5, 100)
# 定义一次函数
k = 1
b = -1.5
y = k * x + b
# 创建图形和坐标轴
fig, ax = plt.subplots(figsize=(5, 3))
# 绘制函数曲线
ax.plot(x, y, linewidth=2)
# 设置坐标轴范围
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
# 将坐标轴放置在中心
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# 添加坐标轴箭头
ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False)
ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False)
# 设置坐标轴标签
ax.set_xlabel('x', fontsize=12, labelpad=-15, x=1.02)
ax.set_ylabel('y', fontsize=12, labelpad=-15, y=1.02, rotation=0)
# 在第一象限线段上方添加函数式标注
x_pos = 5 # 标注的x位置(第一象限)
y_pos = 4.5 # 标注的y位置(在线上方0.5单位)
ax.annotate(
f'$y = kx + b$',
xy=(x_pos, k * x_pos + b), # 箭头指向的点
xytext=(x_pos, y_pos), # 文本位置
arrowprops=dict(arrowstyle='->', color='gray'),
fontsize=12,
ha='center'
)
ax.set_xticks([])
ax.set_yticks([])
# 显示图像
plt.tight_layout()
plt.show()
三、解答题
- 一次函数 y=kx+b (k≠0) 的图像经过点 A(2,3), B(1,1),求一次函数的表达式。y = kx + b \ (k\neq0) \ 的图像经过点 \ A (2, 3), \ B (1, 1), 求一次函数的表达式。y=kx+b (k=0) 的图像经过点 A(2,3), B(1,1),求一次函数的表达式。
solution: 根据以下方程式解得该一次函数的表达式为 y=2x−1y = 2x - 1y=2x−1
from sympy import symbols, Eq, solve
# 定义符号变量
k, b = symbols('k b')
# 定义方程组
eq1 = Eq(2*k + b, 3)
eq2 = Eq(k + b, 1)
# 求解
sol = solve((eq1, eq2), (k, b))
print(f'k = {sol[k]}, b = {sol[b]}')
print(f'一次函数的表达式为:y = {sol[k]}x{sol[b]}')
k = 2, b = -1
一次函数的表达式为:y = 2x-1
- 已知:如图, 菱形 ABCD 中,对角线 AC, BD 交于点 O, AE∥BDAE \parallel BDAE∥BD, DE∥ACDE\parallel ACDE∥AC
- (1) 求证: 四边形 AODE 是矩形
- (2) 若 AB = 8, ∠ABC=60°\angle ABC = 60\degree∠ABC=60°, 求矩形 AODE 的周长
Solution:
(1) According to the definition of a parallelogram: A quadrilateral with two pairs of opposite sides parallel is a parallelogram. Given that AE∥BDAE\parallel BDAE∥BD and DE∥ACDE\parallel ACDE∥AC. Thus, quadrilateral AODE is a parallelogram.
∵\because∵ ABCD is a diamond (rhombus). According to the property of a diamond: The diagonals of a rhombus are perpendicular to each other.
∴\therefore∴ AC⊥BDAC \perp BDAC⊥BD, which means ∠AOD=90°\angle AOD = 90\degree∠AOD=90°
According to the definition of a rectangle: A parallelogram with one right angle is a rectangle. Since parallelogram AODE has ∠AOD=90°\angle AOD = 90\degree∠AOD=90°, therefore quadrilateral AODE is a rectangle.
(2) First, since ABCD is a diamond, AB = BC. Given ∠ABC=60°\angle ABC = 60\degree∠ABC=60°, △ABC\triangle ABC△ABC is an equilateral triangle. So AC=AB=8AC = AB = 8AC=AB=8. And because the diagonals of a diamond bisect each other, OA=12AC=4OA=\frac{1}{2}AC = 4OA=21AC=4.
In diamond ABCD, AC⊥BDAC\perp BDAC⊥BD. In right triangle △AOB\triangle AOB△AOB, using the Pythagorean theorem OB=AB2−OA2OB = \sqrt{AB^{2}-OA^{2}}OB=AB2−OA2. Substitute (AB = 8) and (OA = 4), we get OB=82−42=48=43OB=\sqrt{8^{2}-4^{2}}=\sqrt{48} = 4\sqrt{3}OB=82−42=48=43. Since the diagonals of a diamond bisect each other, OD=OB=43OD = OB = 4\sqrt{3}OD=OB=43.
∵\because∵ AODE is a rectangle, ∴AE=OD=43\therefore AE = OD = 4\sqrt{3}∴AE=OD=43 and DE = OA = 4.
The perimeter of rectangle AODE is 2×(AE+DE)=2×(4+43)=8+832\times(AE + DE)=2\times(4 + 4\sqrt{3}) = 8 + 8\sqrt{3}2×(AE+DE)=2×(4+43)=8+83.
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
# ─────────────────────────
# 1. 顶点坐标
# ─────────────────────────
B = (-2, 0)
A = ( 0, 1)
D = ( 2, 0)
C = ( 0,-1)
O = ( 0, 0)
E = ( 2, 1)
# ─────────────────────────
# 2. 画布
# ─────────────────────────
fig, ax = plt.subplots(figsize=(6, 4))
# (1) 菱形 B-A-D-C
ax.add_patch(
Polygon([B, A, D, C], closed=True,
fill=False, ec='k', lw=1.5)
)
# (2) 对角线 AC 与 BD
ax.plot([A[0], C[0]], [A[1], C[1]], 'k', lw=1.5)
ax.plot([B[0], D[0]], [B[1], D[1]], 'k', lw=1.5)
# (3) 仅补两条边 A-E 和 D-E
ax.plot([A[0], E[0]], [A[1], E[1]], 'k', lw=1.5)
ax.plot([D[0], E[0]], [D[1], E[1]], 'k', lw=1.5)
# ─────────────────────────
# 3. 标注
# ─────────────────────────
for name, (x, y) in dict(A=A,B=B,C=C,D=D,O=O,E=E).items():
if name == "C":
ax.text(x, y-0.15, f' {name}', ha='center', va='center',
fontsize=12, weight='bold')
elif name == "B":
ax.text(x-0.15, y, f' {name}', ha='center', va='center',
fontsize=12, weight='bold')
else:
ax.text(x+0.08, y+0.1, f' {name}', ha='center', va='center',
fontsize=12, weight='bold')
# ─────────────────────────
# 4. 设置显示
# ─────────────────────────
ax.set_aspect('equal')
ax.set_xlim(-2.6, 2.6)
ax.set_ylim(-1.6, 1.6)
ax.axis('off')
plt.show()