from math import sqrt
class
point
(object):
""" 描述平面上的點
"""def__init__
(self, x, y)
:"""
:param x: 橫座標
:param y: 縱座標
"""self.x = x
self.y = y
defmove_to
(self, x, y)
:"""
移動到某點的方法
:param x: 目標點的橫座標
:param y: 目標點的縱座標
"""self.x = x
self.y = y
defmove_by
(self, x, y)
:"""
橫縱座標的增量
:param x: 橫座標增量
:param y: 縱座標增量
"""self.x += x
self.y += y
defdistance_to
(self, other)
:"""
計算該點到另外乙個點的平面距離
"""dx = other.x - self.x
dy = other.y - self.y
return
("%.4f"
% sqrt(
(dx **
2+ dy **2)
))defmain()
: point_1 = point(3,
5)point_1.move_by(7,
5)print
(point_1.x, point_1.y)
point_2 = point(12,
12)print
(point_1.distance_to(point_2)
)if __name__ ==
'__main__'
: main(
)
import time
class
clock
(object):
def__init__
(self, hours, minutes, seconds)
: self.hours = hours
self.minutes = minutes
self.seconds = seconds
defrun(self)
: self.seconds +=
1if self.seconds ==60:
self.seconds =
0 self.minutes +=
1if self.minutes ==60:
self.minutes =
0 self.hours +=
1if self.hours ==24:
self.hours =
0def
show
(self)
:return
("%02d:%02d:%02d"
%(self.hours, self.minutes, self.seconds)
)def
main()
: t = clock(23,
59,58)
while
true
: t.run(
) time.sleep(1)
print
(t.show())
if __name__ ==
'__main__'
: main(
)
python第一天練習
1.有四個數字 1 2 3 4,能組成多少個互不相同且無重複數字的三位數?各是多少?for i in range 1,5 for j in range 1,5 for k in range 1,5 if i k and i j and j k print i,j,k 2.利用條件運算子的巢狀來完成此...
演算法練習 第一天
求1 1!1 3!1 5!1 7!1 n 1 2n 1 下面的演算法時間複雜度為o n 2 public class leijia leicheng sum sum sign a system.out.println sign a system.out.println 結果是 sum 求1 1!1 ...
ctf每日練習 第一天
unserialize3題目鏈結 class xctf code 原理 php反序列化漏洞 執行unserialize 時,先會呼叫 wakeup 當序列化字串中屬性值個數大於屬性個數,就會導致反序列化異常,從而跳過 wakeup 本題 wakeup會執行exit 所以要繞過 class xctf ...