请问如何用Python输入数值是用空格隔开,并将输入的值赋给a,b,c,d。如果用input的话。
请问如何用Python输入数值是用空格隔开,并将输入的值赋给a,b,c,d。如果用input的话。例如这道题...
请问如何用Python输入数值是用空格隔开,并将输入的值赋给a,b,c,d。如果用input的话。例如这道题
展开
展开全部
#拒绝回答一系列代码细节,自行百度学习对应函数
import re
import math
print("Input four numbers seperated by scape, enter `#` for ending input")
myinputs = []
t = input("four numbers:")
while t != "#":
tmp = re.split("\s+",t)
tmp = tuple([float(i) for i in tmp])
if len(tmp) != 4:
print("Wrong input! input another one")
else:
print("Other pair of points or `#` for ending?")
myinputs.append(tmp)
t = input("four numbers:")
print("Input pairs of points:")
for i in myinputs:
print(i)
print("The distances:")
for i in myinputs:
d = math.sqrt((i[0]-i[2])**2 + (i[1]-i[3])**2)
print("%.2f" % d)
'''
例子如下
Input four numbers seperated by scape, enter `#` for ending input
four numbers:1 1 2 2
Other pair of points or `#` for ending?
four numbers:2 3 4 5
Other pair of points or `#` for ending?
four numbers:#
Input pairs of points:
(1.0, 1.0, 2.0, 2.0)
(2.0, 3.0, 4.0, 5.0)
The distances:
1.41
2.83
'''
追问
谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询