В этой программе я продолжаю получать ошибку, которая не определена, хотя я возвращаю ее и вызываю. Я пробовал перечислять имена вещей, но он все равно не работает. Как это исправить? Благодарю. Ошибка приходит на линии в = периметр (sidea, sideb, sidec) и его NameError: имя «sidea» не определенпеременная сторона не определена? Программирование на Python
import math
import sys
def main():
x1, y1 = eval(input("\nEnter the coordinates for the points, x1, y1:"))
x2, y2 = eval(input("Enter the coordinates for the points, x2, y2:"))
x3, y3 = eval(input("Enter the coordinates for the points, x3, y3:"))
dist = distance(x1, y1, x2, y2, x3, y3)
per = perimeter(sidea, sideb, sidec)
are = area(sidea, sideb, sidec, per)
vol = volume(area)
print("\nThe three points are,", x1, y1, "/", x2, y2, "/", x3, y3)
print("\nThe distance between the points is,", "%0.2f" % (dist))
print("\nThe perimter of the triangle is,", "%0.2f" % (per))
print("\nThe area of the triangle is,", "%0.2f" % (are))
print("\nThe volume of the triangle is,", "%0.2f" % (vol))
def distance(x1, y1, x2, y2, x3, y3):
sidea = (((x2-x1)**2) + ((y2- y1)**2))**(1/2)
sideb = (((x3-x2)**2) + ((y3- y2)**2))**(1/2)
sidec = (((x3-x1)**2) + ((y3- y1)**2))**(1/2)
return sidea, sideb, sidec
if ((sidea + sideb) < sidec) and ((sidea + sidec) < sideb) and ((sideb + sidec) < sidea):
print("You cannot create a triangle with these points!")
(sys.exit())
def perimeter(sidea, sideb, sidec):
perimeter = sidea + sideb + sidec
return perimeter
def area(sidea, sideb, sidec, perimeter):
hp = perimeter/2
area = (hp*((hp-sidea)*(hp-sideb)*(hp-sidec)))**(1/2)
return area
def volume(area):
h = eval(input("Enter a positive number for the height of the triangle:"))
if h > 0:
volume = area * h/3
return volume
else:
print("The number entered for the height is not positive!")
(sys.exit())
main()
1. Пожалуйста, исправьте свой отступ. 2. Использование eval при вводе пользователя - это ужасная * плохая идея. 3. Нет, вы не определили sidea в main(). –
Можете ли вы подробно рассказать о том, как я не определил боку, пожалуйста, –
Ну, можете ли вы указать на ту часть, где вы думаете, что вы ее определили? –