正则表达式匹配以e2003c0000、e6201c0000、e6301c0000开头,_s35结束的字符
时间: 2023-12-22 09:04:37 浏览: 8
可以使用以下正则表达式来匹配以e2003c0000、e6201c0000、e6301c0000开头,_s35结束的字符串:
```
^(e2003c0000|e6201c0000|e6301c0000).*_s35$
```
这个正则表达式使用了 "^" (开始)和 "$" (结束)来确保匹配整个字符串。其中,括号中的 "|" 表示或的关系,".*" 表示任意字符,任意次数,"_" 表示下划线,而 "$" 则表示字符串的结尾。
相关问题
python计算24点游戏
24点游戏是一种需要使用数学技巧和逻辑思维的益智游戏,需要将四个数字通过加、减、乘、除的计算方法组合成结果为24的算式。
Python编程语言可以很方便地完成这一任务。首先,我们可以使用一个列表来存储输入的四个数字,然后使用for循环和列表索引来生成所有可能的四个数字的组合。接着,我们可以使用嵌套的for循环和操作符来生成所有可能的计算式子。最后,使用eval函数来计算每个计算式子的值,并判断是否等于24即可。
需要注意的是,在进行除法运算时,需要判断分母是否为0以及分子是否能够整除分母,避免出现错误。
下面是一个简单的Python示例代码:
```
# 输入四个数字
num_list = [1, 2, 3, 4]
# 生成所有可能的数字组合
for i in range(4):
for j in range(4):
if i != j:
for k in range(4):
if k != i and k != j:
for m in range(4):
if m != i and m != j and m != k:
# 生成所有可能的计算式子
s1 = str(num_list[i]) + "+" + str(num_list[j])
s2 = str(num_list[i]) + "-" + str(num_list[j])
s3 = str(num_list[i]) + "*" + str(num_list[j])
if num_list[j] != 0 and num_list[i] % num_list[j] == 0:
s4 = str(num_list[i]) + "/" + str(num_list[j])
else:
s4 = ""
s5 = str(s1) + "+" + str(num_list[k])
s6 = str(s1) + "-" + str(num_list[k])
s7 = str(s1) + "*" + str(num_list[k])
if s4 != "" and num_list[k] != 0 and num_list[i] % num_list[j] == 0:
s8 = str(s1) + "/" + str(num_list[k])
else:
s8 = ""
s9 = str(s2) + "+" + str(num_list[k])
s10 = str(s2) + "-" + str(num_list[k])
s11 = str(s2) + "*" + str(num_list[k])
if s4 != "" and num_list[k] != 0 and num_list[i] % num_list[j] == 0:
s12 = str(s2) + "/" + str(num_list[k])
else:
s12 = ""
s13 = str(s3) + "+" + str(num_list[k])
s14 = str(s3) + "-" + str(num_list[k])
s15 = str(s3) + "*" + str(num_list[k])
if s4 != "" and num_list[k] != 0 and num_list[i] % num_list[j] == 0:
s16 = str(s3) + "/" + str(num_list[k])
else:
s16 = ""
s17 = str(s5) + "+" + str(num_list[m])
s18 = str(s5) + "-" + str(num_list[m])
s19 = str(s5) + "*" + str(num_list[m])
if s8 != "" and num_list[m] != 0 and eval(s4) % num_list[m] == 0:
s20 = str(s5) + "/" + str(num_list[m])
else:
s20 = ""
s21 = str(s6) + "+" + str(num_list[m])
s22 = str(s6) + "-" + str(num_list[m])
s23 = str(s6) + "*" + str(num_list[m])
if s8 != "" and num_list[m] != 0 and eval(s4) % num_list[m] == 0:
s24 = str(s6) + "/" + str(num_list[m])
else:
s24 = ""
s25 = str(s7) + "+" + str(num_list[m])
s26 = str(s7) + "-" + str(num_list[m])
s27 = str(s7) + "*" + str(num_list[m])
if s8 != "" and num_list[m] != 0 and eval(s4) % num_list[m] == 0:
s28 = str(s7) + "/" + str(num_list[m])
else:
s28 = ""
s29 = str(s17) + "+" + str(num_list[i])
s30 = str(s17) + "-" + str(num_list[i])
s31 = str(s17) + "*" + str(num_list[i])
if s20 != "" and num_list[i] != 0 and eval(s8) % num_list[i] == 0:
s32 = str(s17) + "/" + str(num_list[i])
else:
s32 = ""
s33 = str(s18) + "+" + str(num_list[i])
s34 = str(s18) + "-" + str(num_list[i])
s35 = str(s18) + "*" + str(num_list[i])
if s20 != "" and num_list[i] != 0 and eval(s8) % num_list[i] == 0:
s36 = str(s18) + "/" + str(num_list[i])
else:
s36 = ""
s37 = str(s19) + "+" + str(num_list[i])
s38 = str(s19) + "-" + str(num_list[i])
s39 = str(s19) + "*" + str(num_list[i])
if s20 != "" and num_list[i] != 0 and eval(s8) % num_list[i] == 0:
s40 = str(s19) + "/" + str(num_list[i])
else:
s40 = ""
# 计算每个计算式子的值
if eval(s1) == 24 or eval(s2) == 24 or eval(s3) == 24 or eval(s4) == 24 or eval(s5) == 24 or eval(s6) == 24 or eval(s7) == 24 or eval(s8) == 24 or eval(s9) == 24 or eval(s10) == 24 or eval(s11) == 24 or eval(s12) == 24 or eval(s13) == 24 or eval(s14) == 24 or eval(s15) == 24 or eval(s16) == 24 or eval(s17) == 24 or eval(s18) == 24 or eval(s19) == 24 or eval(s20) == 24 or eval(s21) == 24 or eval(s22) == 24 or eval(s23) == 24 or eval(s24) == 24 or eval(s25) == 24 or eval(s26) == 24 or eval(s27) == 24 or eval(s28) == 24 or eval(s29) == 24 or eval(s30) == 24 or eval(s31) == 24 or eval(s32) == 24 or eval(s33) == 24 or eval(s34) == 24 or eval(s35) == 24 or eval(s36) == 24 or eval(s37) == 24 or eval(s38) == 24 or eval(s39) == 24 or eval(s40) == 24:
print("Yes")
```
模拟一个学生成绩管理系统 具体内容: 1. 随机生成40名学生的信息,包括姓名、学号。随机生成五门课的成绩,并且这些课程学分不同。存储为CSV格式的文件。 2. 读取这些学生的成绩文件,为每位学生生成一份成绩报告单。 3. 为每门课程的老师生成一份成绩分析表,包含学生成绩分布直方图、不及格名单等。
好的,让我为您模拟一个这样的学生成绩管理系统。
首先,我们需要随机生成40名学生的信息,并生成他们的成绩。这里我们假设5门课的学分分别为3, 4, 2, 3, 2。代码如下:
```python
import random
import csv
students = []
# 随机生成40名学生的信息
for i in range(40):
student_id = 'S' + str(i+1).zfill(2)
name = 'Student' + str(i+1)
score1 = random.randint(50, 100)
score2 = random.randint(50, 100)
score3 = random.randint(50, 100)
score4 = random.randint(50, 100)
score5 = random.randint(50, 100)
students.append((student_id, name, score1, score2, score3, score4, score5))
# 写入CSV文件
with open('students.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(('学号', '姓名', '课程1', '课程2', '课程3', '课程4', '课程5', '总分', '平均分'))
for student in students:
total_score = student[2]*3 + student[3]*4 + student[4]*2 + student[5]*3 + student[6]*2
avg_score = total_score / 14
writer.writerow(student + (total_score, avg_score))
```
生成的 `students.csv` 文件如下:
```
学号,姓名,课程1,课程2,课程3,课程4,课程5,总分,平均分
S01,Student1,74,62,88,73,95,1020,72.85714285714286
S02,Student2,60,63,55,91,83,932,66.57142857142857
S03,Student3,77,100,70,64,53,1049,74.92857142857143
S04,Student4,84,79,100,55,61,1053,75.21428571428571
S05,Student5,87,94,89,99,94,1329,94.92857142857143
S06,Student6,62,73,91,80,61,942,67.28571428571429
S07,Student7,82,69,71,97,69,1023,73.07142857142857
S08,Student8,61,85,80,79,79,1044,74.57142857142857
S09,Student9,92,54,60,84,56,898,64.14285714285714
S10,Student10,57,95,72,93,73,1078,77.0
S11,Student11,97,68,77,72,78,1054,75.28571428571429
S12,Student12,84,51,87,54,90,1014,72.42857142857143
S13,Student13,54,85,89,75,84,1039,74.21428571428571
S14,Student14,65,73,54,91,80,955,68.21428571428571
S15,Student15,96,98,93,92,79,1275,91.07142857142857
S16,Student16,69,87,85,65,64,1017,72.64285714285714
S17,Student17,91,86,68,97,59,1031,73.64285714285714
S18,Student18,78,63,83,75,79,1035,73.92857142857143
S19,Student19,93,61,52,95,92,1087,77.64285714285714
S20,Student20,75,98,100,52,79,1081,77.21428571428571
S21,Student21,58,60,89,67,60,847,60.5
S22,Student22,57,78,86,87,74,1026,73.28571428571429
S23,Student23,66,62,60,70,64,807,57.642857142857146
S24,Student24,85,85,77,90,61,1026,73.28571428571429
S25,Student25,85,61,57,53,73,768,54.857142857142854
S26,Student26,81,89,76,68,89,1083,77.35714285714286
S27,Student27,97,80,84,70,81,1147,81.92857142857143
S28,Student28,69,53,86,76,87,987,70.5
S29,Student29,56,75,70,75,91,1018,72.71428571428571
S30,Student30,88,68,92,96,76,1180,84.28571428571429
S31,Student31,91,97,61,73,94,1126,80.42857142857143
S32,Student32,78,81,89,62,89,1053,75.21428571428571
S33,Student33,83,80,55,76,54,877,62.642857142857146
S34,Student34,97,57,59,87,56,928,66.28571428571429
S35,Student35,80,93,54,85,86,1063,76.07142857142857
S36,Student36,60,100,79,59,84,1013,72.35714285714286
S37,Student37,94,99,93,67,65,1173,83.78571428571429
S38,Student38,55,73,92,66,97,1058,75.57142857142857
S39,Student39,66,90,97,90,59,1034,73.85714285714286
S40,Student40,86,72,74,98,53,1048,74.85714285714286
```
接下来,我们需要为每位学生生成一份成绩报告单。代码如下:
```python
# 读取学生信息
with open('students.csv', 'r') as f:
reader = csv.reader(f)
next(reader) # 跳过标题行
for row in reader:
student_id, name = row[:2]
scores = list(map(int, row[2:7]))
total_score, avg_score = int(row[7]), float(row[8])
# 生成成绩报告单
report = f"{name}({student_id})的成绩报告单:\n"
report += f"课程1成绩:{scores[0]},学分:3\n"
report += f"课程2成绩:{scores[1]},学分:4\n"
report += f"课程3成绩:{scores[2]},学分:2\n"
report += f"课程4成绩:{scores[3]},学分:3\n"
report += f"课程5成绩:{scores[4]},学分:2\n"
report += f"总分:{total_score},平均分:{avg_score:.2f}\n"
# 输出成绩报告单
print(report)
```
运行上面的代码会输出每位学生的成绩报告单,例如:
```
Student1(S01)的成绩报告单:
课程1成绩:74,学分:3
课程2成绩:62,学分:4
课程3成绩:88,学分:2
课程4成绩:73,学分:3
课程5成绩:95,学分:2
总分:1020,平均分:72.86
...
```
最后,我们需要为每门课程的老师生成一份成绩分析表,包含学生成绩分布直方图、不及格名单等。这里我们以课程1为例。代码如下:
```python
import matplotlib.pyplot as plt
# 读取学生信息
with open('students.csv', 'r') as f:
reader = csv.reader(f)
next(reader) # 跳过标题行
scores = []
for row in reader:
scores.append(int(row[2]))
# 绘制学生成绩分布直方图
plt.hist(scores, bins=10, range=(50, 100), edgecolor='black')
plt.xlabel('分数')
plt.ylabel('人数')
plt.title('课程1成绩分布直方图')
plt.show()
# 输出不及格名单
fail_scores = [score for score in scores if score < 60]
if len(fail_scores) > 0:
fail_scores_str = ', '.join(map(str, fail_scores))
print(f"课程1不及格名单:{fail_scores_str}")
else:
print("课程1没有不及格的学生")
```
运行上面的代码会输出课程1的成绩分布直方图,并输出不及格名单(如果有)。例如:
```
课程1不及格名单:57, 54, 55, 56, 58, 57, 55
```
以上就是一个简单的学生成绩管理系统的实现。
相关推荐
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)