簡體   English   中英

流程結束,退出代碼為0

[英]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

在哪里可以看到輸出?

為了清楚起見,我還添加了一個附件。

謝謝

在此處輸入圖片說明

問題是由於缺少縮進, resetcalculate_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM