码迷,mamicode.com
首页 > 其他好文 > 详细

sys.stdin的三种方式

时间:2016-05-09 14:13:27      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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))

 

sys.stdin的三种方式

标签:

原文地址:http://www.cnblogs.com/hhh5460/p/5473494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!