CPU数据表记录与删除
类型:程序题

题目说明

import sqlite3
import datetime
import psutil   #获取cpu当前占比
conn = sqlite3.connect("        ①        ")
creatsql = "create table Rate(ID integer primary key, Rate float,updatetime time)"
        ②
cur.execute(creatsql)
conn.commit()
insertsql = "insert into Rate(ID,Rate,updatetime) values(%d,%f,'%s')"
checksql = "select * from Rate"
for x in range(0,10):
    nowtime = datetime.datetime.now()
    nowtime = nowtime.strftime('%Y-%m-%d %H:%M:%S')
    cpu_per = float(psutil.cpu_percent(1))
    cur.        ③        (insertsql  % (x,cpu_per,nowtime))
    conn.commit()
cur.execute(checksql)
data = cur.fetchall()
delsql="delete from Rate where ID=%d"
cur.execute(delsql %1)
conn.commit()
        ④
conn.close()

评分标准

(1)cpu.db;(2分) (2)cur = conn.cursor();(3分) (3)execute;(2分) (4)cur.close()。(3分)

代码编辑器 加载中...
留空使用题目默认限制
{{resultStatus.text}}
正在加载运行记录...
乐编题库AI助手
人工客服
微信扫码联系客服
历史对话
{{ s.title || '未命名对话' }}
{{ s.created_at }}
暂无历史对话
我能帮助你什么?