1 Star 0 Fork 0

坚持不懈的大白/Python 测试

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
面向对象专项编程.py 5.69 KB
一键复制 编辑 原始数据 按行查看 历史
liuze 提交于 2023-12-04 09:31 . test
# 1 . 空调
# class AirConditioning:
#
# def __init__(self,brand,price):
# self.__brand = brand
# # 品牌
# self.__price = price
# # 价格
#
# def getBrand(self):
# return self.__brand
#
# def getPrice(self):
# return self.__price
#
# def setBrand(self,brand):
# self.__brand = brand
#
# def setPrice(self,price):
# self.__price = price
#
# def powerOn(self):
# print('空调开机了!')
#
# def shutDown(self,minute):
# print(f'空调将在{minute}分钟后自动关闭...')
#
# # 重写 object 下的方法 __str__
# def __str__(self):
#
# return f'品牌:{self.__brand}-价格:{self.__price}'
#
#
# if __name__ == '__main__':
# a = AirConditioning('格力',12000)
# # 创建出空调对象
# print(a)
# # 空调的品牌和价格并打印到控制台上
# a.powerOn()
# # 开机
# a.shutDown(3)
# # 关机
# 2. 打电话
# import time
#
#
# class MobilePhone:
# def __init__(self, remaining_phone_bill, brand, battery, px, time2, jf):
# self.__remaining_phone_bill = remaining_phone_bill
# # 剩余话费
# self.__brand = brand
# # 手机品牌
# self.__battery = battery
# # 电池容量
# self.__px = px
# # 屏幕大小
# self.__time2 = time2
# # 待机时长
# self.__jf = jf
#
# # 积分
#
# def sendMessage(self, content):
# # 发消息
# print(f'发送消息->{content}')
#
# def playPhone(self,phoneNumber,time3):
# # 打电话
# if len(phoneNumber.strip()) == 0:
# print('所拨电话号码为空!')
# elif self.__remaining_phone_bill < 1:
# print('话费余额不足!')
# else:
# print('电话拨通!')
# money = 0
# jf = 0
# for i in range(0,time3+1):
# if i < 10:
# money += 1
# jf += 15
# elif i < 20:
# money += 0.8
# jf += 39
# else:
# money += 0.65
# jf += 48
# time.sleep(0.1)
# self.__jf += jf
# self.__remaining_phone_bill -= money
# print('通话结束!')
# print(f'本次通话花费为:{money}元,所获积分为{jf}')
#
#
# if __name__ == '__main__':
# # remaining_phone_bill, brand, battery, px, time2, jf
# a = MobilePhone(20,'oppo','80%','360x500',100,0)
#
# # a.sendMessage('哈哈')
# a.playPhone('123456',20)
# 3. 需求编程
# class Student:
#
# def __init__(self, xh='', name='', gender='', height='', weight='', score='', address='', phone=''):
# self.__xh = xh
# # 学号
# self.__name = name
# # 姓名
# self.__gender = gender
# # 性别
# self.__height = height
# # 身高
# self.__weight = weight
# # 体重
# self.__score = score
# # 成绩
# self.__address = address
# # 家庭地址
# self.__phone = phone
# # 电话号码
#
#
# def study(self,minute):
# print('学习时间为:',minute)
#
# # 学习
#
# def play(self,gameName):
# print(f'玩游戏{gameName}')
#
# # 玩游戏
#
# def code(self,line):
# print(f'今日编写代码行数:{line}')
# # 编程
#
#
# def sum2(self, *args):
# ans = 0
# for i in range(len(args)):
# ans += args[i]
# print(ans)
# # 求和
#
#
# if __name__ == '__main__':
# a = Student()
# a.play('哈哈')
# a.sum2(2,3,4,)
# class Car:
# # 车型号,车轮数,车身颜色,车重量,油箱存储大小
# def __init__(self, carId, wheel, carColor, carWeight, carOil):
# self.__carId = carId
# self.__wheel = wheel
# self.__carColor = carColor
# self.__carWeight = carWeight
# self.__carOil = carOil
#
# # 跑(要求参数传入车的具体功能,比如越野,赛车)
#
# def run(self, ability):
# print(ability)
# class noteBookComputer:
# # 型号,待机时间,颜色,重量,cpu型号,内存大小,硬盘大小
# def __init__(self,type=None,time2=None,color=None,weight=None,cpuType=None,memorySize=None,hard_disk_size=None):
# self.__type = type
# self.__time2 = time2
# self.__color = color
# self.__weight = weight
# self.__cpuType = cpuType
# self.__memorySize = memorySize
# self.__hard_disk_size = hard_disk_size
#
#
# def playGame(self,gameName):
# print(f'玩游戏:{gameName}!')
#
# def bg(self):
# print('办公!')
#
#
# if __name__ == '__main__':
# a = noteBookComputer()
# a.bg()
# a.playGame('王者荣耀')
class Monkey:
def __init__(self,type=None,gender=None,color=None,weight=None):
# 类别,性别,身体颜色,体重。
self.__type = type
self.__gender = gender
self.__color = color
self.__weight = weight
# 造火(要求传入造火的材料:比如木棍还是石头),学习事物(要求参数传入学习的具体事物,可以不止学习一种事物)
def fireMaking(self,material):
print(f'使用{material}造火!')
def study(self,*args):
print('正在学习事物:',end='')
for i in range(len(args)):
print(args[i],end=',')
print()
if __name__ == '__main__':
a = Monkey()
a.fireMaking('打火石')
a.study('做饭','玩游戏')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/il_li/python-testing.git
git@gitee.com:il_li/python-testing.git
il_li
python-testing
Python 测试
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385