python:create time object
# encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2024/6/18 17:53 # User : geovindu # Product : PyCharm # Project : EssentialAlgorithms # File : Person.py # explain : 学习 class person(object): def __init__(self): """ """ self.RealName="" self.Sex="" def __init__(self,realname,sex): """ """ self.RealName = realname self.Sex = sex @property def RealName(self): """ :return: """ return self.RealName @RealName.setter def RealName(self,realname): """ :param realname: :return: """ self.RealName=realname @property def Sex(self): """ :return: """ return self.Sex @Sex.setter def Sex(self,sex): """ :param sex: :return: """ self.Sex=sex def toString(self): """ :return: """ return f"{self.RealName},{self.Sex}"
引用:
from Model.Person import person
调用:
a=[3,1,1] b=a b[0]=1 print(a) # a 的值也改了。输出是1,1,1 print(b)#输出是1,1,1 print(id(a),id(b)) #ID一样的 p=person p.RealName="geovindu" p.Sex="F" a=p b=p p.RealName="涂聚文" print(a.RealName)
a = [3, 1, 1] b = list(a) # 或者 b = a[:] b[0] = 1 print(a) # 输出: [3, 1, 1],因为a没有被修改 print(b) # 输出: [1, 1, 1],因为b是a的一个副本,并且被修改了ID 不一样
# encoding: utf-8 # 版权所有 2024 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # Datetime : 2024/6/15 18:59 # User : geovindu # Product : PyCharm # Project : pyBaiduAi # File : TimeInfo.py # explain : 学习 class TimeInfo(object): """ """ def __init__(self): """ 实例化 """ self.day = 0 """ 天 """ self.hour = 0 """ 小时 """ self.minute = 0 """ 分 """ self.second = 0 """ 秒 """ ''' def __init__(self,hour: int, minute: int, second: int): """ :param hour: :param minute: :param second: """ self.hour = hour self.minute = minute self.second = second ''' @property def Day(self): """ 天 :return: """ return self.day @Day.setter def Day(self, day:int): """ 天 :param day: :return: """ self.day = day @property def Hour(self): """ 小时 :return: """ return self.hour @Hour.setter def Hour(self, hour:int): """ 小时 :param hour: :return: """ self.hour = hour @property def Minute(self): """ 分 :return: """ return self.minute @Minute.setter def Minute(self, minute:int): """ 分 :param minute: :return: """ self.minute = minute @property def Second(self): """ 秒 :return: """ return self.second @Second.setter def Second(self, second:int): """ 秒 :param second: :return: """ self.second = second def toString(self): """ 字符串全显示属性 :return: """ return f"{self.day} day {self.hour} hour {self.minute} minute {self.second} second"
# encoding: utf-8 # 版权所有 2024 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # Datetime : 2024/6/15 18:56 # User : geovindu # Product : PyCharm # Project : pyBaiduAi # File : CalculateTime.py # explain : 学习 import sys import os from Model.TimeInfo import TimeInfo class CalculateTime(object): """ 计算秒花具体时间 """ def __init__(self): """ 实例化 """ self.time = 0 def __init__(self, time: int): """ 实例化 :param second: """ self.time = time def calculate(self) -> TimeInfo: """ 根据秒数计算天,小时,分,秒 :return: 返回结果要求的天,小时,分,秒 实体类 """ info = TimeInfo() ''' 小时 hour = self.time // 3600 minute = (self.time - hour * 3600) // 60 second = self.time % 60 inf.hour = hour inf.minute = minute inf.second = second ''' day = self.time // (24 * 3600) hour = self.time % (24 * 3600) // 3600 minute = self.time % (24 * 3600) % 3600 // 60 second = self.time % 60 info.day = day info.hour = hour info.minute = minute info.second = second # return (day,hour,minute,second) return info ''' def calculate(self, time: int) -> TimeInfo: """ :param second: :return: """ inf=TimeInfo() hour = time // 3600 minute = (time - hour * 3600) // 60 second = time % 60 inf.hour = hour inf.minute = minute inf.second = second return inf '''
引用:
from Common.CalculateTime import CalculateTime from Model.TimeInfo import TimeInfo
调用:
a=0 b=10 print(a and b) print(a or b) a=1 b=10 print(a and b) print(a or b) #调用 info=TimeInfo() cn=CalculateTime(114520) info=cn.calculate() print(info.toString())
pen = turtle.Turtle() pen.color('red') d = 500 r = d / math.tan(math.radians(67.5)) pen.up() pen.goto(0, -300) pen.seth(45) pen.begin_fill() pen.down() pen.fd(d) pen.circle(r, 225) pen.left(180) pen.circle(r, 225) pen.fd(d) pen.end_fill() # Move turtle to air pen.up() # Move turtle to a given position pen.setpos(-68, 95) # Move the turtle to the ground pen.down() # Set the text color to lightgreen pen.color('lightgreen') # Write the specified text in # specified font style and size pen.write("我愛ICT,我開♥", font=( "Verdana", 12, "bold")) # 空心 pen.color('red') d = 500 r = d / math.tan(math.radians(67.5)) pen.up() pen.goto(0, -500) pen.seth(45) pen.down() pen.fd(d) pen.circle(r, 225) pen.left(180) pen.circle(r, 225) pen.fd(d)
pen = turtle.Turtle() screen = turtle.Screen() screen.title('Golden Dragon Curve - PythonTurtle.Academy') screen.setup(1000, 1000) screen.setworldcoordinates(-1000, -1000, 1000, 1000) pen.speed(0) pen.hideturtle() pen.pencolor('gold') screen.bgcolor('royal blue') screen.tracer(0, 0) golden_ratio = (1 + 5 ** 0.5) / 2 r1 = r = (1 / golden_ratio) ** (1 / golden_ratio) r2 = r1 ** 2 angle1 = math.acos((1 + r ** 2 - r ** 4) / (2 * r)) angle2 = math.acos((1 + r ** 4 - r ** 2) / (2 * r ** 2)) print(r1, r2, math.degrees(angle1), math.degrees(angle2)) def golden_dragon(x1, y1, x2, y2, turn, n): dist = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 if dist < 1: pen.goto(x2, y2) return angle = math.atan2(y2 - y1, x2 - x1) if turn: px = x1 + dist * r1 * math.cos(angle + angle1) py = y1 + dist * r1 * math.sin(angle + angle1) else: px = x1 + dist * r2 * math.cos(angle - angle2) py = y1 + dist * r2 * math.sin(angle - angle2) golden_dragon(x1, y1, px, py, True, n - 1) golden_dragon(px, py, x2, y2, False, n - 1) pen.up() pen.goto(-500, -200) pen.down() golden_dragon(-500, -200, 700, -200, True, 3) screen.update()
pen = turtle.Turtle() # Set initial position pen.penup() pen.left(90) pen.fd(200) pen.pendown() pen.right(90) # flower base pen.fillcolor("red") pen.begin_fill() pen.circle(10, 180) pen.circle(25, 110) pen.left(50) pen.circle(60, 45) pen.circle(20, 170) pen.right(24) pen.fd(30) pen.left(10) pen.circle(30, 110) pen.fd(20) pen.left(40) pen.circle(90, 70) pen.circle(30, 150) pen.right(30) pen.fd(15) pen.circle(80, 90) pen.left(15) pen.fd(45) pen.right(165) pen.fd(20) pen.left(155) pen.circle(150, 80) pen.left(50) pen.circle(150, 90) pen.end_fill() # Petal 1 pen.left(150) pen.circle(-90, 70) pen.left(20) pen.circle(75, 105) pen.setheading(60) pen.circle(80, 98) pen.circle(-90, 40) # Petal 2 pen.left(180) pen.circle(90, 40) pen.circle(-80, 98) pen.setheading(-83) # Leaves 1 pen.fd(30) pen.left(90) pen.fd(25) pen.left(45) pen.fillcolor("green") pen.begin_fill() pen.circle(-80, 90) pen.right(90) pen.circle(-80, 90) pen.end_fill() pen.right(135) pen.fd(60) pen.left(180) pen.fd(85) pen.left(90) pen.fd(80) # Leaves 2 pen.right(90) pen.right(45) pen.fillcolor("green") pen.begin_fill() pen.circle(80, 90) pen.left(90) pen.circle(80, 90) pen.end_fill() pen.left(135) pen.fd(60) pen.left(180) pen.fd(60) pen.right(90) pen.circle(200, 60) pen.done()
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)