1、现在有如下流程:A->B->C->D->E->F,要求根据输入的参数从制定的流程执行下去
"""
File: 01流程执行.py
Author: chde_wang
Date: 2020-08-16 18:51:35
Description:将输入存储到列表中,方便判断下一输入是否为之前的第二阶段,当前一阶段满足且输入为F时,输入结束
"""
import sys
process_list = ['A', 'B', 'C', 'D', 'E', 'F']
input_list = []
while True:
print("若要退出请按quit!")
input_char = input("请输入流程:")
if input_char == 'quit':
sys.exit()
else:
if input_char in process_list:
for char_name in input_char:
if char_name == 'A':
input_list.append(char_name)
print("下一流程为B")
elif char_name == 'B' and input_list[-1] == 'A':
input_list.append(char_name)
print("下一流程为C")
elif char_name == 'C' and input_list[-1] == 'B':
input_list.append(char_name)
print("下一流程为D")
elif char_name == 'D' and input_list[-1] == 'C':
input_list.append(char_name)
print("下一流程为E")
elif char_name == 'E' and input_list[-1] == 'D':
input_list.append(char_name)
print("下一流程为F")
elif char_name == 'F' and input_list[-1] == 'E':
input_list.append(char_name)
print("流程结束")
sys.exit()
else:
print("输入错误!", end='')else:
print("输入错误,请重新输入!若要退出请按quit!")
修改:增加input_list 不为空控制:
"""
File: 01流程执行.py
Author: chde_wang
Date: 2020-08-16 18:51:35
Description:将输入存储到列表中,方便判断下一输入是否为之前的第二阶段
"""
import sys
process_list = ['A', 'B', 'C', 'D', 'E', 'F']
input_list = []
while True:
print("若要退出请按quit!")
input_char = input("请输入流程:")
if input_char == 'quit':
sys.exit()
else:
if input_char in process_list:
if input_char == 'A':
input_list.append(input_char)
print("下一流程为B")
elif input_list:
if input_char == 'B' and input_list[-1] == 'A':
input_list.append(input_char)
print("下一流程为C")
elif input_char == 'C' and input_list[-1] == 'B':
input_list.append(input_char)
print("下一流程为D")
elif input_char == 'D' and input_list[-1] == 'C':
input_list.append(input_char)
print("下一流程为E")
elif input_char == 'E' and input_list[-1] == 'D':
input_list.append(input_char)
print("下一流程为F")
elif input_char == 'F' and input_list[-1] == 'E':
input_list.append(input_char)
print("流程结束")
sys.exit()
else:
print("输入错误!", end='')else:
print("输入错误,请重新输入!若要退出请按quit!")
2、数据库题目:数据库记录行转列
现有数据库记录如下:
文章图片
文章图片
实现方式1-静态max实现:
SELECT
`Name`,
max( CASE WHEN SUBJECT = '语文' THEN Score ELSE 0 END ) AS 语文,
max( CASE WHEN SUBJECT = '数学' THEN Score ELSE 0 END ) AS 数学,
max( CASE WHEN SUBJECT = '英语' THEN Score ELSE 0 END ) AS 英语,
max( CASE WHEN SUBJECT = '生物' THEN Score ELSE 0 END ) AS 生物
FROM
test_a
GROUP BY
NAME;
实现方式2-静态sum实现:
SELECT
`Name`,
sum( CASE WHEN SUBJECT = '语文' THEN Score ELSE 0 END ) AS 语文,
sum( CASE WHEN SUBJECT = '数学' THEN Score ELSE 0 END ) AS 数学,
sum( CASE WHEN SUBJECT = '英语' THEN Score ELSE 0 END ) AS 英语,
sum( CASE WHEN SUBJECT = '生物' THEN Score ELSE 0 END ) AS 生物
FROM
test_a
GROUP BY
NAME;
实现方式3-动态实现:
SET @sql = NULL;
SELECT
GROUP_CONCAT( DISTINCT CONCAT( 'MAX(IF(a.Subject = ''', a.Subject, ''',a.Score, 0)) AS ''', a.Subject, '''' ) ) INTO @sql
FROM
mysql.test_a a;
SET @sql = CONCAT('Select Name,', @sql, 'From test_a a GROUP BY a.Name');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
注:前后test_a 的别名必须一致,否则出错。
【python-week5】参考自https://blog.csdn.net/wqc19920906/article/details/79791322?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
推荐阅读
- python3 week4
- python之异常处理
- Python 可变参数*args和**kwargs
- python基础学习|Python 装饰器理解
- jupyter notebook安装rise库无法显示按钮的解决方案