1. for line in sys.stdin:
import sys sys.stdout.write('根据两点坐标计算直线斜率k,截距b:\n') for line in sys.stdin: if line == '\n': break x1, y1, x2, y2 = (float(x) for x in line.split()) k = (y2 - y1) / (x2 - x1) b = y1 - k * x1 sys.stdout.write('斜率:{},截距:{}\n'.format(k, b))
2. while True:
line = sys.stdin.readline()
import sys sys.stdout.write('根据两点坐标计算直线斜率k,截距b:\n') while True: line = sys.stdin.readline() if line == '\n': break x1, y1, x2, y2 = (float(x) for x in line.split()) k = (y2 - y1) / (x2 - x1) b = y1 - k * x1 sys.stdout.write('斜率:{},截距:{}\n'.format(k, b))
3. while True:
line = input()
print('根据两点坐标计算直线斜率k,截距b:') while True: line = input() if line == '\n': break x1, y1, x2, y2 = (float(x) for x in line.split()) k = (y2 - y1) / (x2 - x1) b = y1 - k * x1 print('斜率:{},截距:{}'.format(k, b))
本文后半部分转自罗兵博客园博客,原文链接:http://www.cnblogs.com/hhh5460/p/5473494.html,如需转载请自行联系原作者