-2
我在寫矢量求解程序,角度測量不計算。它有時可以工作,但有時不會。量級始終有效。我認爲它可能在某個地方存儲變量,或者將一個數字計算爲0.它會給出一個錯誤,儘管我不知道。Python矢量計算器(數學導入)
import time
import sys
import math
import random
import pygame
flag = 0
# Main
while True:
print ("------------")
int(flag)
flag += 1
if flag > 0:
str(flag)
print "Set: "+str(flag)
x = int(input("Enter x1: "))
y = int(input("Enter y1: "))
x2 = int(input("Enter x2: "))
y2 = int(input("Enter y2: "))
b1 = x2 - x
b1 = b1 ** 2
b2 = y2 - y
b2 = b2 ** 2
b3 = b1 + b2
b4 = (x2 - x)
b4 = abs(b4)
b5 = (y2 - y)
b5 = abs(b5)
b6 = b5/b4
magnitude = math.sqrt(b3)
magnitude = str(magnitude)
angle = math.degrees(math.atan(b6))
angle = str(angle)
print "Magnitude: "+str(magnitude)
print "Angle: "+str(angle)
if flag > 2:
sys.exit()