class Students:
def __init__(self,name, age,*score):
self.name = name
self.age = age
self._score = score
def getname(self):
return self.name
def getage(self):
return self.age
@property
def score(self):
return max(self._score)
class Auto:
def __init__(self, tyre, weight, speed):
self.tyre = tyre
self.weight = weight
self.speed = speed
def speed_up(self):
print("汽车加速了!")
def speed_down(self):
print("汽车减速了!")
def stop(self):
print("汽车减速了!")
a1 = Auto(4,'1T','155km/h')
class CarAtuto(Auto):
def __init__(self, air_cond, CD):
self.air_cond = air_cond
self.CD = self.CD
c2 = CarAtuto('有','无')
class User:
def __init__(self,firstname, lastname, sex, age):
self.firstname = firstname
self.lastname = lastname
self.sex = sex
self.age = age
def describe_user(self):
print(self.__dict__)
def greetuser(self):
print("%s %s早上好!" % self.firstname, self.lastname)
class Admin(User):
def __init__(self, privileges:list,firstname, lastname, sex, age):
super().__init__(firstname,lastname, sex, age )
self._privileges = privileges
@property
def show_privileges(self):
print("管理员的权限如下:")
for value in self._privileges:
return print(value)
count = 0
class Person:
def __init__(self,count):
count += 1
- 歌词解析器
def splits(str1, *str2):
list1 = []
new_str = ''
for char1 in str1:
if char1 in str2:
list1.append(new_str)
new_str = ''
else:
new_str += char1
list1.append(new_str)
while '' in list1:
list1.remove('')
return list1
def exchange(list1):
count = int(len(list1) / 3)
dict1 = {}
for value in range(count):
a1 = 3 * (value + 1) - 3
a2 = 3 * (value + 1) - 2
a3 = 3 * (value + 1) - 1
time = int(list1[a1]) * 3600 + int(list1[a2]) * 60 + int(list1[a3])
dict1.update({time: list1[-1]})
return dict1
def a(x):
global value
for key in x:
value = key
return value
def my_list(list):
list_new = []
for value in list:
for key in value:
list_new.append([key, value[key]])
return list_new
class MusicAnalysis:
def __init__(self,address):
self.address = address
def read(self):
##提取txt文本中的歌词并保存为字典##
with open(self.address, 'r', encoding='utf-8') as f:
content = f.readline()
dict_all = {}
while content:
# 切割单行歌词
list1 = splits(content, '[', ':', '.', ']', '\n')
# 将时间转化为毫秒,并和对应的歌词添加进字典dict1
dict_all.update(exchange(list1))
content = f.readline()
# 转换为列表 list_all
list_all = []
for key in dict_all:
list_all.append({key: dict_all[key]})
# 对列表list1_all进行sort排列
list_all.sort(key=a)
list_all_ = my_list(list_all)
return list_all_
def show(self):
for value1 in self.read():
print(value1[1])
def search(self,time):
try:
time1 = splits(time, ':', '.')
time_new = int(time1[0])*3600 + int(time1[1])*60 + int(time1[2])
list1 = self.read()
count = -1
for value1 in list1:
if time_new > value1[0]:
count += 1
continue
else:
return print(list1[count][1])
except:
print("请按格式正确输入时间")
p1 = MusicAnalysis('files/歌词.txt')
p1.show()
print('==================')
p1.search('02:00.00')