在 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 人评分
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:682 |
校门外的树 (C语言代码)浏览:1113 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:563 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:724 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:664 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:463 |
用筛法求之N内的素数。 (C语言代码)浏览:646 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:594 |
打印十字图 (C语言代码)浏览:2701 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:553 |