- 博客(9)
- 收藏
- 关注
原创 pymysql连接本地数据库
首先要创建表 meal_order_detail1import pymysqlconn = pymysql.connect( host='localhost', port=3307, user='root', password='root', database='ba', charset='utf8')#连接本地数据库cursor = conn.cursor()#创建游标sql1 = """show tables;"""cursor.execute(sql
2020-12-18 00:53:08 1346
原创 flask的简单求和网页
app = Flask(name)@app.route("/")@app.route("/hello")def hello():return “Hello world! This is a web application by Flask.”def hello():#return render_template(“index.html”)return “”" 输入两个数求和 使用表单计算两个数的和
2020-12-18 00:40:20 348
原创 python爬取财富
爬取内容:财富500强http://www.fortunechina.com/fortune500/c/2020-08/10/content_37214.htmimport requestsfrom bs4 import BeautifulSoup # 网页解析 获取数据r = requests.get('http://www.fortunechina.com/fortune500/c/2020-08/10/content_372148.htm')#以下为对请求回的信息进行'utf-8'编码r
2020-12-18 00:20:58 258
原创 python爬虫爬取标题及内容
新闻网 wanghttp://www.cfbond.com/cfkx/index.htmlfrom urllib.request import urlopen, Requestfrom bs4 import BeautifulSoup # 网页解析 获取数据import re # 正则表达式 进行文字匹配import randomurl = 'http://www.cfbond.com/cfkx/index.html'hd = {'User-Agent': 'Mozilla/5.0
2020-12-18 00:12:44 2017
原创 python词频
path = 'C://Users/25077/Desktop/Walden.txt'with open(path,'r') as text: #去掉文字首位的标点符号,并把首字母大写转换成小写 words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()] #将列表用set函数转换成集合 words_index = set(words) #创建一单词为
2020-12-18 00:09:59 88
原创 python从小到大排序
list1 = [1,2,6,0.3,2,0.5,-1,2.4]for i in range(len(list1)-1): #循环遍历从0开始到倒数第二个元素下标 for j in range(len(list1)-1-i): #循环遍历从0开始,每次循环将最大数放到最末尾 if list1[j] > list1[j+1]: #判断两个相邻数的大小,大的往后面排,小的往前面排 list1[j],list1
2020-12-17 23:57:33 4471 1
原创 文本文件操作
#文本文件操作编写一个程序demo.py,要求运行该程序后,生成demo_new.py文件,其中内容与demo.py一样,只是在每一行的后面加上行号以#开始,并且所有行的#符号垂直对齐。filename = 'demo.py'with open(filename, 'r') as fp: lines = fp.readlines()maxLength = len(max(lines, key=len))lines = [line.rstrip().ljust(maxLength)+'#'
2020-12-17 23:48:05 363
原创 超简单的点名程序
#超简单的点名程序 import pandas as pdimport randomimport collectionsdf = pd.read_excel('C:\\Users\\Administrator\\Desktop\\数应191名单.xlsx')data = collections.OrderedDict(zip(df.iloc[:,1],df.iloc[:,2]))print(data)f = int(input("请输入抽取的人数"))#老师输入抽取点名的人a = ra
2020-12-17 23:41:20 507
原创 约瑟夫循环——数数字游戏
约瑟夫循环——数数字游戏如一个班有28人,123循环书数数到3的人淘汰,最后剩下的两个人是哪两个list = [n for n in range(1,28)]fin = listt=1index=0while(fin.__len__()!=2): t+=1; index=(index+2)%fin.__len__(); if(t%1==0): fin.pop(index) print(fin) t=2; print(fin
2020-09-17 20:55:17 146
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人