-
guest说:
用c语言编写程序计算某区间内素数的个数cnt,并按所求素数的值从大到小的顺序,再计算其间隔减、加之和,即第1个素数-第2个素数+第3个素数-第4个素数+第5个素数……的sum值
,最后输出cnt和sum的值。
#include
#includeint main(void)
{
int i, j, k, cnt = 0, sum = 0;
int a, b;
printf("请输入区间(a, b):");
scanf("%d, %d", &a, &b);
int prime[b - a + 1];
for (i = 0; i = a && ij <= b)
prime[ij - a] = 1;
}
for (k = 0; k <= b - a; k++)
{
if (prime[k] == 0)
{
cnt++;
sum += k + a;
printf("%d\t", k + a);
}
}
printf("\n素数的个数cnt:%d\n", cnt);
printf("素数的和sum:%d\n", sum);
return 0;
} -
guest说:
用fastapi+sqlalchemy+pydantic+mysql搭建一个项目,展示出合理的目录结构
├─app
│ ├─main.py
│ ├─models.py
│ ├─schema.py
│ ├─crud.py
│ └─utils.py
├─config
│ └─config.py
├─migrations
│ ├─env.py
│ ├─script.py.mako
│ ├─versions
│ └─README
├─tests
│ ├─conftest.py
│ └─test_main.py
└─.env -
guest说:
用fastapi+sqlalchemy+pydantic+mysql搭建一个简单的学生信息系统,要求代码合理,目录结构合理
import uvicorn
from fastapi import FastAPI, Request, Response
from pydantic import BaseModel
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker初始化数据库连接:
engine = create_engine('mysql+pymysql://root:123456@127.0.0.1:3306/test')
创建对象的基类:
Base = declarative_base()
定义Student对象:
class Student(Base):
# 表的名字:
tablename = 'student'# 表的结构: id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(20)) age = Column(Integer) gender = Column(String(20))
初始化数据库连接:
Base.metadata.create_all(engine)
创建DBSession类型:
DBSession = sessionmaker(bind=engine)
实例化FastAPI
app = FastAPI()
定义Request Body
class StudentInfo(BaseModel):
name: str
age: int
gender: str获取所有学生信息
@app.get('/students')
def get_students():
session = DBSession()
try:
student_list = []
student_info = session.query(Student).all()
for student in student_info:
student_list.append({
'id': student.id,
'name': student.name,
'age': student.age,
'gender': student.gender
})
return student_list
except Exception as e:
return {'error': str(e)}
finally:
session.close()添加学生信息
@app.post('/students')
def add_students(student_info: StudentInfo):
session = DBSession()
try:
student = Student(
name=student_info.name,
age=student_info.age,
gender=student_info.gender
)
session.add(student)
session.commit()
session.refresh(student)
return {
'id': student.id,
'name': student.name,
'age': student.age,
'gender': student.gender
}
except Exception as e:
return {'error': str(e)}
finally:
session.close()更新学生信息
@app.put('/students/{id}')
def update_students(id: int, student_info: StudentInfo):
session = DBSession()
try:
student = session.query(Student).filter(Student.id == id).one()
student.name = student_info.name
student.age = student_info.age
student.gender = student_info.gender
session.commit()
return {
'id': student.id,
'name': student.name,
'age': student.age,
'gender': student.gender
}
except Exception as e:
return {'error': str(e)}
finally:
session.close()删除学生信息
@app.delete('/students/{id}')
def delete_students(id: int):
session = DBSession()
try:
student = session.query(Student).filter(Student.id == id).one()
session.delete(student)
session.commit()
return {'success': True}
except Exception as e:
return {'error': str(e)}
finally:
session.close()if name == 'main':
uvicorn.run(app, host="127.0.0.1", port=8000) -
guest说:
用fastapi搭建一个blog系统的目录结构
├── app │ ├── api │ │ ├── auth.py │ │ ├── blog.py │ │ └── users.py │ ├── config.py │ ├── __init__.py │ ├── main.py │ ├── models │ │ ├── auth.py │ │ ├── blog.py │ │ └── users.py │ ├── schemas │ │ ├── auth.py │ │ ├── blog.py │ │ └── users.py │ ├── tests │ │ ├── auth.py │ │ ├── conftest.py │ │ ├── blog.py │ │ └── users.py │ └── utils │ ├── auth.py │ └── users.py ├── docker-compose.yml ├── Dockerfile ├── main.py ├── Pipfile ├── Pipfile.lock └── README.md
-
peng111说:
MST一B800和MST一B100车库门电机区别
MST一B800和MST一B100车库门电机的区别:
-
功率不同:MST一B800的电机功率为800W,而MST一B100的电机功率为100W。
-
品牌不同:MST一B800的电机由德国MST品牌生产,而MST一B100的电机由德国Sommer品牌生产。
-
价格不同:MST一B800的电机价格更高,而MST一B100的电机价格更低。
-
加速度不同:MST一B800的电机拥有更高的加速度,而MST一B100的电机拥有更低的加速度。
-
速度不同:MST一B800的电机具有更快的速度,而MST一B100的电机具有更慢的速度。
-