美文网首页
python homework

python homework

作者: Sakura_flower | 来源:发表于2018-10-18 21:01 被阅读0次
    一、.定义一个学生类。有属性:姓名、年龄、成绩(语文,数学,英语)[每课成绩的类型为整数]方法:a. 获取学生的姓名:getname() b. 获取学生的年龄:getage()c. 返回3门科目中最高的分数。get_course()
    class student:
         def __init__(self, name = '' , age = 0, score = {}):
         self.name = name
         self.age = age
         self.score = score
    
    class score:
         def __init__(self, math = 0, Chinese = 0, English = 0):
         self.math = math
         self.Chinese = Chinese
         self.English = English
    
         def get_name(self):
              return self.name
         def get_age(self):
              return self.age
         def get_course(self,score):
              max_sco = score['Chinese']
              for course in score:
                   if max_sco < score[course]:
                        max_sco = score[course]
              return max_sco
    
    if __name__ == __'main'__:
         sco1 = score( 130, 123, 90 )
         print(sco1.__dict__)
         stu1 = student('薇恩' , 18, sco1.__dict__)
         print('学生姓名为:%s' stu1.get_name())
         print('学生年龄为:%s' stu1.get_age())
         print('三科中成绩最高的是:%s' stu1.get_course(sco1.__dict__))
    
    二、写一个类,其功能是:1.解析指定的歌词文件的内容 2.按时间显示歌词 提示:歌词文件的内容一般是按下面的格式进行存储的。歌词前面对应的是时间,在对应的时间点可以显示对应的歌词
    import time
    
    def runtime():
        time = ''
        millisecond = 0
        second = 0
        minute = 0
        with open('./lanlianhua.txt', 'r', encoding = 'utf-8') as llh:
            lyric = llh.readlines()
            while minute < 3:
                millisecond+= 1
                if millisecond == 100:
                    second += 1
                    millisecond = 0
                if second == 60:
                    minute += 1
                    second = 0
                timea = '[' + str(minute).rjust(2, '0') + ':' + str(second).rjust(2, '0') + '.' + str(millisecond).rjust(2, '0') + ']'
                for llh in lyric:
                    if timea in llh:
                        print(llh[llh.rfind(']')+1:])
                        time.sleep(0.8)
                        break
    
    
    if __name__ == '__main__':
        runtime()
    

    相关文章

      网友评论

          本文标题:python homework

          本文链接:https://www.haomeiwen.com/subject/qgiszftx.html