本文主要是介绍《python语言程序设计》2018版第7章第10题设计一个名为time的类,包括hour minute second,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#main代码段
def main():a = int(time.time())total_second = int(a)current_second = total_second % 60total_minutes = total_second // 60current_minute = total_minutes % 60total_hours = total_minutes // 60current_hour = total_hours % 24b = exCode07.Time(current_hour,current_minute,current_second,55550505)print(b.time_show())print(b.get_time())main()
我对这个结果没有信息
#class 类的代码段
class Time:def __init__(self, hour=0, minute=0, second=0, elapse=0):self.__hour = hourself.__minute = minuteself.__second = secondself.__elapse = elapsedef set_hour(self, hour):return self.__hourdef set_minute(self, minute):return self.__minutedef set_second(self, second):return self.__seconddef set_elapse(self, elapse):return self.__elapsedef get_hour(self):return self.__hourdef get_minute(self):return self.__minutedef get_second(self):return self.__seconddef time_show(self):a = self.__hourb = self.__minutec = self.__secondreturn f"Current time is {a+8}:{b}:{c}"def get_time(self):a = int(self.__elapse)total_second = int(a)current_second = total_second % 60total_minutes = total_second // 60current_minute = total_minutes % 60total_hours = total_minutes // 60current_hour = total_hours % 24return f"{current_hour + self.__hour+8} : {current_minute+self.__minute} : {current_second+self.__second}"
这篇关于《python语言程序设计》2018版第7章第10题设计一个名为time的类,包括hour minute second的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!