ValueError: too many values to unpack (expected 6)
的错误原因之一:
在自己变量输入没有问题的时候是否有考虑没有用eval函数转化字符类型为数值类型。
#求三角形的三个角度,画图显示角度
import turtle
import math
#x1 , y1 , x2 , y2 , x3 , y3 = 0 , 0 , 0 , 100 , 100 , 0
x1 , y1 , x2 , y2 , x3 , y3 = eval( input('请输入坐标:') )#没有加入eval
#eval 的作用就是讲输入的字符串转化为数字
'''
x1 , y1 , x2 , y2 , x3 , y3 = input('请输入坐标:')
没有eval的时候就会出现下面错误
Traceback (most recent call last):
File "D:/pycharm/code/11-08/11-08-01.py", line 6, in <module>
x1 , y1 , x2 , y2 , x3 , y3 = input('请输入坐标:')
ValueError: too many values to unpack (expected 6)
'''
a = ( (x2 - x1)**2 + (y2 - y1)**2 )**0.5
b = ( (x3 - x1)**2 + (y3 - y1)**2 )**0.5
c = ( (x3 - x2)**2 + (y3 - y2)**2 )**0.5
cosA = (b**2 +c**2 -a**2) / (2*b*c)
cosB = (c**2 + a**2 -b**2) / (2*a*c)
cosC = (a**2 + b**2 - c**2) / (2*a*b)
A = int( math.degrees( math.acos(cosA) ) )
B = int( math.degrees( math.acos(cosB) ) )
C = int( math.degrees( math.acos(cosC) ) )
print(cosA,cosB,cosC)
print(A,B,C)
turtle.showturtle()
turtle.penup()
turtle.goto(x1,y1)
turtle.write('角C= ' + str(C))
turtle.pendown()
turtle.goto(x2,y2)
turtle.write('角B= ' + str(B))
turtle.goto(x3,y3)
turtle.write('角A= ' + str(A))
turtle.goto(x1,y1)
turtle.hideturtle()
turtle.done()