首页 > 编程语言 >Python7-实战

Python7-实战

时间:2022-10-27 14:14:44浏览次数:38  
标签:实战 __ code self month print query Python7

实战01(修改手机默认语言)

1 class Phone: 2 '''手机类''' 3 def __init__(self,language = '英文'): 4 if language =='英文': 5 print("智能手机的默认语言为" + language) 6 else: 7 print("将智能手机的默认语言设置为" + language) 8 Phone() 9 Phone('中文')

 

 

实战02(给信用卡设置默认密码)

1 class Card: 2 '''信用卡类''' 3 def __init__(self,number,code = "123456"): 4 if code == "123456": 5 print("信用卡" + str(number) + "的默认密码为"+ str(code)) 6 else: 7 print("重置信用卡" + str(number) + "的密码为" + str(code)) 8 Card("4013735633800642") 9 Card("4013735633800642","168779")

 

 

实战03(打印每月销售明细)

1 class SaleHandler: 2 '''销售管理类''' 3 def __init__(self): 4 self.__sale_data = { 5 "2":[('T0001','笔记本电脑'), 6 ('T0002','荣耀6X'), 7 ('T0003','iPad'), 8 ('T0004','荣耀V9'), 9 ('T0005','MACBook')]} #{key:value} 10 def querySaleList(self,query_month): 11 '''根据输入月份,查询商品明细''' 12 if query_month in self.__sale_data: 13 print("%s月份商品销售明细如下:" % query_month) 14 for item in self.__sale_data[query_month]: 15 print("商品编号:%s 商品名称:%s" % item) 16 else: 17 print("该月份没有销售数据或输入月份有误!") 18 print("------销售明细-----") 19 sh = SaleHandler() 20 while True: 21 month = input("请输入要查询的月份(例如1、2、3等):") 22 if month == 'quit': 23 break 24 25 sh.querySaleList(month)

 

标签:实战,__,code,self,month,print,query,Python7
From: https://www.cnblogs.com/ron312/p/16832003.html

相关文章