Python 第2页

Python_函数练习题

1. 编写一个函数,该函数接收两个数字作为输入,并返回这两个数字的最大公约数。 def fun(x, y): while y != 0: temp = y y = x % y x = temp return x num1 = int(input('请输入第一个数字: '...
北梦的头像-北梦の博客SVIP北梦2年前
01807

Python上课笔记_20231204

1.计票机制 p = {} while True: xm = input('请输入选手姓名(输入0退出):') if xm == '0': break ps = int(input('请输入票数:')) p[xm] = ps items = p.items() li = [] for i in items: li.ap...
北梦的头像-北梦の博客SVIP北梦2年前
0596

Python_练习_24.3.28

class ShoppingCart: def __init__(self): self.items = [] def add_items(self, item): if item in items_price: self.items.append(item) print(f'{item}已添加到购物车') else: print(f'没有...
北梦的头像-北梦の博客SVIP北梦1年前
0785

Python第一学期期末考试_个人解题分享

由于众所周知的原因
北梦的头像-北梦の博客SVIP北梦1年前
01435

python_课堂作业_5.11

import re # 1.re.split()和字符串中的split()函数一样,用来切割字符串 # str.split()函数不支持正则表达式和多个切割符号 # re.split()函数可以通过正则表达式切割字符串,支持使用多个分隔...
X.蔡徐坤的头像-北梦の博客X.蔡徐坤11个月前
1212

python_小作业_24.6.20

1.定义一个Box类,有width, height, depth三个属性,init()和get_Volume()(求体积)两个方法。其中init()方法用于获得初始化属性值,width, height, depth分别为5,6,7. (1)定义get_Volume()...
北梦的头像-北梦の博客SVIP北梦10个月前
0251

Python上课笔记

编写列表推导式1、将一组数字列表[1,2,3,4,5,6,7,8],每个数字都平方并除以2.l1 = [1, 2, 3, 4, 5, 6, 7, 8] print([i * i / 2 for i in l1])2、将一组字符串列表['apple','banana','cherry'],...
北梦的头像-北梦の博客SVIP北梦2年前
12041

Python_模拟银行对接mysql_24.6.14

1.创建数据库和数据表 import pymysql CREATE_SCHEMA_SQL = 'CREATE SCHEMA bank' CREATE_TABLE_SQL = '''CREATE TABLE account( account_id varchar(20) not null, account_passwd char(6) not...
北梦的头像-北梦の博客SVIP北梦10个月前
0421

Python-pymysql删除

import pymysql zwy = pymysql.connect(host='localhost', user='root', password='123456789', db='world') cursor = zwy.cursor() zwy.commit() delete_sql = 'delete from student where sna...
珊瑚海的头像-北梦の博客珊瑚海10个月前
0141

Python-pymysql修改

import pymysql zwy = pymysql.connect(host='localhost', user='root', password='123456789', db='world') cursor = zwy.cursor() zwy.commit() update_sql = '''update student set sname = ...
珊瑚海的头像-北梦の博客珊瑚海10个月前
0151