Python共40篇
上课笔记以及平时作业记录

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

Python递归案例

把10不断处以2,直到不能除为止,打印每次的结果 def a(num): if num == 0: return 0 else: print(num) a(num // 2) a(10) 兔子数列 def f(month): if month < 3: return 1 else: return f(m...
北梦的头像-北梦の博客SVIP北梦2年前
011815

Python作业:函数

公约数# 编写一个函数,该函数接收两个数字作为输入,并返回这两个数字的最大公约数。 def gcd(a, b): while b != 0: a, b = b, a % b return a num1 = int(input('请输入一个整数:')) num2 = i...
珊瑚海的头像-北梦の博客珊瑚海2年前
014114

Python课案例:计票机制

y = {} x = [] print('输入quit表示选手成绩录入完毕') while True: name = input('输入选手名称: \n') if name == 'quit': break score = float(input('请输入选手票数: \n')) y[name] = score...
珊瑚海的头像-北梦の博客珊瑚海2年前
022013

Python求两数的最大公约数

import math while True: num1 = int(input('请输入第一个整数')) num2 = int(input('请输入第二个整数')) if num1 > num2: while num2 != 0: num1, num2 = num2, num1 % num2 print(num1) e...
珊瑚海的头像-北梦の博客珊瑚海2年前
012312

python 24.3.21 作业

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

Python_练习_24.3.15

class Friend: def __init__(self): self.friend_li = {} # 实例方法 def welcome(self): print('欢迎来到好友管理系统') print('1.添加好友') print('2.删除好友') print('3.展示好友') print(...
北梦的头像-北梦の博客SVIP北梦1年前
012911
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年前
0959

Python_练习_24.3.8

1.写出下列题目中的pyhon语句 定义一个Employee类(员工) 在员工类中定义类属性age(年龄)为40 定义一个方法displayCount(),输出“公司最高工资” 通过类Employee修改类属性age的值=35 在方...
北梦的头像-北梦の博客SVIP北梦1年前
01199

Python_封装和继承_练习

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