У меня есть задание, где я должен создать программу, которая вычисляет результирующую силу. Дело в том, что он работает без проверки, но когда я начал вводить функцию проверки, он продолжает возвращаться как «нетип», поэтому программа не может скомпилировать
Код:
import math
def main():
M1,D1 = get_values()
M2,D2 = get_values()
RFX = rx(M1,M2,D1,D2)
RFY = ry(M1,M2,D1,D2)
ResultantMagnitude = resultant(RFX,RFY)
ResultantDirection = direction_r(RFY,RFX)
display(ResultantMagnitude,ResultantDirection)
def get_values():
print('\nPlease input the needed values for the resultant \n ')
M = float (input('Magnitude of Force = '))
M = validate_direction(M)
D = float (input('Direction of Force = '))
D = validate_direction(D)
return M,D
def validate_direction(D1):
while D1 > 360 or D1 < 0:
print("Invalid Direction, enter again : ")
D1=float(input())
def validate_magnitude(M1):
while M1 < 0:
print("Invalid Magnitude, enter again : ")
M1=float(input())
def rx(M1,M2,D1,D2):
#Force 1
if D1 <= 90 or D1 == 360:
F1x = ((M1 * math.cos(math.radians(D1))))
elif D1 <= 180 or D1 > 90:
F1x = ((abs(M1)* math.cos(math.radians(D1))))
elif D1 <= 270 or D1 >180:
F1x = ((M1 * math.cos(math.radians(D1))))
else:
F1x = ((M1 * math.cos(math.radians(D1))))
#force 2
if D2 <= 90 or D2 == 360:
F2x = ((M2 * math.cos(math.radians(D2))))
elif D2 <= 180 or D2 > 90:
F2x = ((abs(M2)* math.cos(math.radians(D2))))
elif D2 <= 270 or D2 >180:
F2x = ((M2 * math.cos(math.radians(D2))))
else:
F2x = ((M2 * math.cos(math.radians(D2))))
RFX = (F1x + F2x)
return RFX
def ry(M1,M2,D1,D2):
#Force 1
if D1 <= 90 or D1 == 360:
F1y = (M1 * math.sin(math.radians(D1)))
elif D1 <= 180 or D1 > 90:
F1y = (abs(M1) * math.sin(math.radians(D1)))
elif D1 <= 270 or D1 >180:
F1y = (M1 * math.sin(math.radians(D1)))
else:
F1y = (abs(M1) * math.sin(math.radians(D1)))
#force 2
if D2 <= 90 or D2 == 360:
F2y = (M2 * math.sin(math.radians(D2)))
elif D2 <= 180 or D2 > 90:
F2y = (abs(M2) * math.sin(math.radians(D2)))
elif D2 <= 270 or D2 >180:
F2y = (M2 * math.sin(math.radians(D2)))
else:
F2y = (abs(M2) * math.sin(math.radi`enter code here`ans(D2)))
RFY = (F1y + F2y)
return RFY
def resultant(RFX,RFY):
ResultantMagnitude = (math.sqrt((pow(RFX,2) + pow(RFY,2))))
return ResultantMagnitude
def direction_r(RFY,RFX):
ResultantDirection =math.degrees(math.atan((RFY)/(RFX)))
return ResultantDirection
def display(ResultantMagnitude,ResultantDirection):
print('\n')
print('The magnitude of the resultant is {:0.2f}'.format(ResultantMagnitude), 'Newton')
print('The direction of the resultant is {:0.2f}'.format(ResultantDirection) , 'Degrees')
if __name__ == '__main__':
main()
ошибка :
Please input the needed values for the resultant
Magnitude of Force = 200
Direction of Force = 200
Please input the needed values for the resultant
Magnitude of Force = 200
Direction of Force = 200
Traceback (most recent call last):
File "C:/IntelliJ/Python/Activity1/Test Force.py", line 78, in <module>
main()
File "C:/IntelliJ/Python/Activity1/Test Force.py", line 5, in main
RFX = rx(M1,M2,D1,D2)
File "C:/IntelliJ/Python/Activity1/Test Force.py", line 27, in rx
if D1 <= 90 or D1 == 360:
**TypeError: '<=' not supported between instances of 'NoneType' and 'int'**
Process finished with exit code 1
"D1", "D2", "M1", "M2" продолжают возвращаться как нетип, это работает, когда я удаляю D1 =, D2 =, M1 =, M2 =. но при этом проверка не будет переопределять код