在 Python3 中舍弃了 Python2 中的 raw_input() 的输入方式,读入的数据全部是字符串类型,需要使用 int() 强转即可,

input()读入一行数据,strip() 去除两端空格, split() 默认按照空格分割


map方式的原理:

map(function, iterable, ...)

  Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed,function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items. If function is None, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.

map的第一个参数可以是 function.


第一种(有多组输入数据,但是没有告诉你有多少组):

# 1)、
while True:
    try:
        a, b = input().strip().split()
        print(int(a) + int(b))
    except :
        break
# 2)、
# 是另外一种读入方式,下面都会按照这种方式        
while True:
    try:
        a, b = map(int, input().strip().split())
        print(a+ b)
    except :
        break

第二种(输入一个整数,告诉我们接下来有多少组数据)

t = int(input().strip())
for i in range(t):
    a, b = map(int, input().strip().split())
    print(a+ b)

第三种(有多组输入数据,没有告诉你有多少组,但是题目告诉你遇见什么结束)

while True:
    a, b = map(int, input().strip().split())
    if a == 0 and b == 0:
        break
    print(a+ b)

第四种(有多组输入数据,并告诉我们有多少组和遇见什么结束)

t = int(input().strip())
for i in range(t):
    a, b = map(int, input().strip().split())
    if a == 0 and b == 0:
        break
    print(a+ b)

有什么问题,请在下面进行留言

待续....

点赞(3)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论