python
Charonmomo
这个作者很懒,什么都没留下…
展开
-
python - 求商和余数“/“ “//“ “%“运算符的区别
/表示浮点数除法, 结果中保留小数点num = 5num //= 2print(num) # 输出 2.5//表示整数除法,返回不大于结果的一个最大的整数.num = 5num //= 2print(num) # 输出 2%取余数参考: https://blog.csdn.net/data8866/article/details/62884210/补充而在C/C++中,"/ " 算术运算符的计算结果通常是根据参与运算的两边的数据决定的, 比如:任意一边是浮点数, 结果原创 2021-11-01 15:06:47 · 10885 阅读 · 0 评论 -
python - list和np.array寻找出现最多次的元素和次数
首先要知道list和np.array是不同的, 所以使用的方法也是不同的. 如果对一个np,array使用list的方法是会报错的.import numpy as np# listtest = [1,2,3,4,5,6,7,8,9,0,1,1,2,2,3,3,4,4,5,5,6,6,0,1]# 输出数组中出现最多次数的元素, 以及它出现的次数a = max(test,key=test .count)c = test.count(a)print("出现最多次数的元素, 以及它出现的次数分别为原创 2021-07-30 17:14:59 · 2024 阅读 · 0 评论 -
python -列表中嵌套多个字典, 如何取出字典的重复值
描述在一个列表中嵌套了字典, 如下:weights = [{'subject': 2896, 'distance': 0.8343115868747709}, {'subject': 2834, 'distance': 0.8147950789314828}, {'subject': 2937, 'distance': 0.7866704974194655}]需求:如果subject有重复, 则取出重复的subject值如果没有重复, 则取出所有subject中第一个值代码import p原创 2021-07-22 20:25:22 · 3875 阅读 · 0 评论 -
python - 数据库查询条件有多个值时如何处理 where id in (, , ,)
这个问题困扰了好久, 没有在网上找到全一点的处理方法. 现在解决了, 记录一下处理的办法:#ask customer to order foodprint("\n which kind of pizza would you like to order? Please input the index number of them." "\n (note: Please separate them with commas, like 1,2,3. When you have finished t原创 2021-01-01 17:14:42 · 860 阅读 · 0 评论 -
python -从数据库中获取数据并以表格的形式在控制台显示
方法是导入pandas的库, 使用DataFram制表.控制台直接显示返回的所有数据库数据:#show food itemsshowFood = " select id,name,note,price from foodlist;"result = cur.execute(showFood)print("Welcome! We now have",result,"kinds of pizza now. " "You could find the index number, name,原创 2021-01-01 17:13:05 · 2495 阅读 · 0 评论 -
python - TypeError: combat(sume,sumu) missing 2 required positional arguments: sume,sumu
问题描述写程序的时候遇到了一个问题, 题目的背景为:描述语句定义一个函数, 开始游戏前玩家的初始分数为sumu,对手的初始分数为sume. 游戏中玩家和对手轮流投骰子三次, 相加后分数最高的人胜出def combat(sume,sumu)定义一个投骰子的按钮,对手先投骰子(这里对手为电脑), 玩家投骰子后按钮变为"wait",即等待电脑投骰子, 玩家投骰子时按钮为"roll dice".dice = tk.Button(window, text=“wait”, comman原创 2021-01-01 17:12:09 · 537 阅读 · 4 评论 -
python - mysql 数据库增删改查
建表在mysql数据库中建立一张表userlist:(不知道为什么保存的时候height, weight的值会变)数据库连接# connect to mysqlconn = sql.connect( host = 'localhost', port = 3306, user = 'root', passwd = 'toor', db = 'pizzaordersys',)#get cursorcur = conn.cursor()插入数据tm原创 2021-01-01 17:11:15 · 247 阅读 · 1 评论 -
python - .py文件打包成.exe文件, 发送给别人
python文件打包成.exe文件有两种方式参考:pyinstaller打包Nuitka打包环境环境描述OSWindows10 64位python3.7pycharm2019安装pyinstallerwindows + R 打开命令框, 输入:pip install pyinstaller这里不要升级.打包查看命令帮助:pyinstaller -h查看命令版本:pyinstaller -v#打包方式# 1)结果多个文件pyins原创 2020-11-20 15:38:13 · 2230 阅读 · 1 评论 -
python - mysql 参数传递
1. 不传递参数conn = MySQLdb.connect(user="root",passwd="123456",host="192.168.101.23",db="cmdb")orange_id = 98sql = "select * from orange where id=%s" % orange_idcursor = conn.cursor(sql)cursor.execute()2. 传递参数color = "yellow"sql = "select * from ora转载 2020-11-12 17:56:25 · 2009 阅读 · 1 评论 -
python - 用input()接收同行输入的多个参数
print("\n please input the numbers:")orderFood = list(map(int, input().split(',')))print(orderFood)split(’’) 单引号中的内容即为用户输入参数的分隔符, 比如变成空格时, 结果如下图所示:print("\n please input the numbers:")orderFood = list(map(int, input().split(' ')))print(orderFood)原创 2020-11-12 16:11:43 · 4803 阅读 · 2 评论 -
python - input()用户输入的值不合法则要求重新输入
#input and judge genderwhile True: gender = input("Please input your gender (m for male, f for female):") if(gender =='m' or gender == 'f'): break else: print("Error! you must input a valid letter!Please try again!\n")原创 2020-11-12 15:44:35 · 9636 阅读 · 0 评论 -
python 3 连接MySQL数据库
环境我的python是3.7版本, 数据库是8.0.17操作系统pythonMySQLwin103.78.0.17安装pymysql可以用pip安装或者直接在pycharm里安装,pycharm安装比较直观, 代码里直接import就可以import pymysql as sql 或者在打开 [file] -> [settings] ->[project 名称] ->[project interpreter] , 点击右边"+"键 (insta原创 2020-11-12 15:36:02 · 119 阅读 · 0 评论 -
TypeError: sequence item 0: expected str instance, int found - [python] list/str的互转问题
报错发生在list -> str的过程中,使用orderFood接收了用户输入的int值,orderFood = list(map(int, input().split(',')))# list ->stringorderFoodStr = ''.join(orderFood)print(orderFoodStr)错报是因为join函数的对象应该是str而不能是int,需要借助map()函数将list内每个元素转为str型,再join().orderFood = list(m原创 2020-11-11 18:03:28 · 875 阅读 · 1 评论 -
Anconda的包无法整合到pycharm 解决方法
之前一直以为是点击第二个conda environment ,一直都是失败,后来才发现应该点击的是第三个system interpreter。点击system interpreter后,选择python.exe所在的路径,点击ok就可以了。...原创 2019-08-08 14:05:31 · 1090 阅读 · 3 评论 -
python3.7环境,安装Anaconda
下载Anaconda安装包官网下载或是在清华大学镜像站下载,我安装的是下面这个版本:安装过程配置环境将anaconda的scripts文件夹路径添加到环境变量中。如果命令行输入输出如图所示则安装成功:为了避免可能发生的错误, 我们在命令行输入conda upgrade --all 先把所有工具包进行升级。(也可以不安装升级)打开pycharm,如图点击,发现...原创 2019-08-08 11:18:35 · 805 阅读 · 0 评论 -
pycharm 2019最新版本安装步骤
官网下载地址:http://www.jetbrains.com/pycharm/download/#section=windows下载社区版就可以了。1.下载好以后,点击安装,记得修改安装路径,我这里放的是D盘,Next2.选择配置3.选择JetBrains4....原创 2019-07-28 15:36:40 · 5116 阅读 · 0 评论 -
如何使用myeclipse2017运行python (eclipse环境下python配置)
一.安装python1.官网下载官网地址: https://www.python.org/download→windows,根据电脑版本选择32/64位x86为32位,x86-64为64位;下载 executable installer (exe运行的安装)2.勾选“Add Python 3.7 to PATH", 否则需要手动配置地址。3.全选尽量不要安装在C盘,选择其...原创 2019-07-27 23:56:41 · 2238 阅读 · 1 评论 -
python学习笔记(二) 文件、异常、函数(filter,map,reduce,zip)
一、文件(一)写入文件(二)读取文件(三)文件指针二、异常的检测和处理三、函数(一)函数定义和调用(二)函数传参(三)变量作用域(四)lambda表达式四、python内建函数(一)fliter(二)map(三)reduce(四)zip五、闭包原创 2019-07-30 15:37:37 · 250 阅读 · 0 评论 -
python学习笔记(一) 序列、条件、循环、字典
一、序列(一)字符串(二)元组(三)列表二、条件语句三、循环语句(一)for循环(二)while循环(三)for循环中的if嵌套(四)while循环中的if嵌套四、字典的定义和操作五、列表推导式与字典推导式(一)列表推导式(二)字典推导式原创 2019-07-29 22:58:08 · 356 阅读 · 0 评论