ice


私信TA

用户名:image

访问量:8413

签 名:

等  级
排  名 571
经  验 4156
参赛次数 8
文章发表 5
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

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

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

待续....

 

0.0分

3 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区