Python 第2页

Python_封装和继承_练习

使用继承机制,为Car类创建两个子类:赛车(Racing_Car)类和公交车(Bus)类。为Car类定义属性最高时速(Top_speed)属性和核载人数(Nuclear_Number)方法,并分别通过子类对象调用父类中的成...
北梦的头像-北梦の博客SVIP北梦1年前
0798

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年前
0795

Python_练习_24.3.22

class School_number(): def __init__(self, name, age): self.name = name self.age = age def describe(self): print(f'我的名字是{self.name},我的年龄是{self.age}') class Student(School...
北梦的头像-北梦の博客SVIP北梦1年前
07815
python购物车练习-北梦の博客

python购物车练习

class Shopping: def __init__(self): self.car = [] def shopping_car(self, itme): self.car.append(itme) def shopping_del(self, itme): self.car.remove(itme) def shopping_all(self): if...
koniaoer的头像-北梦の博客koniaoer1年前
0789

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年前
0606

Python_练习_24.4.7

练习1 def GetAge(age): try: if age <= 0: raise Exception('输入的年龄不符合要求') except ValueError: print('年龄必须大于0') raise GetAge(-1) 练习2 num_one = int(input('请输入被除...
北梦的头像-北梦の博客SVIP北梦1年前
0541

Python_练习_24.3.29

选择题 try-except-else-finally练习 编写程序,按用户输人的半径计算圆的面积,若半径为负值则抛出异常
北梦的头像-北梦の博客SVIP北梦1年前
0431

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作业加注释6月6日-北梦の博客

python作业加注释6月6日

import pymysql my = pymysql.connect( host='127.0.0.1', user='root', password='123456789', db='world' ) cur = my.cursor() cur.execute('DROP TABLE IF EXISTS minyan;') sql = '''create...
koniaoer的头像-北梦の博客koniaoer10个月前
0361

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