[英]Process finished with exit code 0
我有這個:
import math
class Point:
def move(self, x, y):
self.x = x
self.y = y
def reset(self):
self.move(0, 0)
def calculate_distance(self, other_point):
return math.sqrt(
(self.x - other_point.x)**2 +(self.y - other_point.y)**2)
# how to use it:
point1 = Point()
point2 = Point()
point1.reset()
point2.move(5,0)
print(point2.calculate_distance(point1))
assert (point2.calculate_distance(point1) == point1.calculate_distance(point2))
point1.move(3,4)
print(point1.calculate_distance(point2))
print(point1.calculate_distance(point1))
所以我希望它像這樣打印:
5.0
4.472135955
0.0
但是在控制台的pycharm中,它僅顯示以下內容:
Process finished with exit code 0
在哪里可以看到輸出?
為了清楚起見,我還添加了一個附件。
謝謝
問題是由於缺少縮進, reset
和calculate_distance
函數不在Point
類中。
嘗試這個。 現在,這些函數是Point類的方法,並且所有函數都正常運行:
import math
class Point:
def move(self, x, y):
self.x = x
self.y = y
def reset(self):
self.move(0, 0)
def calculate_distance(self, other_point):
return math.sqrt((self.x - other_point.x)**2 +(self.y - other_point.y)**2)
# how to use it:
point1 = Point()
point2 = Point()
point1.reset()
point2.move(5,0)
print(point2.calculate_distance(point1))
assert (point2.calculate_distance(point1) == point1.calculate_distance(point2))
point1.move(3,4)
print(point1.calculate_distance(point2))
print(point1.calculate_distance(point1))
有一個名為“ python控制台”的窗口。 腳本的輸出應該在這里...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.