Python3的一些基本输入输出

# python3

# 基本输入输出

#学会使用split()的使用是关键,input()的返回值一定是字符类型

 

.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

1 # Example Input
2 # 1 5
3 # Example Output
4 # 6
5  
6 a = []
7 for x in input().split():
8     a.append(int(x))
9 print(sum(a))

直接一行输出

1 print(sum(int(x) for x in input().split()))

 

.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

 1  # Example Input
 2  # 1 5
 3  # 10 20
 4  # Example Output
 5  # 6
 6  # 30
 7  
 8   while True:
 9       line = input()
10      if line:
11          print(sum(int(x) for x in line.split()))
12      else:
13          break

 

 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

 1  # Example Input
 2  # 2
 3  # 1 5
 4  # 10 20
 5  # Example Output
 6  # 6
 7  # 30
 8  
 9  N = int(input())
10  while(N):
11      print(sum(int(x) for x in input().split()))
12      N -= 1

 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

 1 # Example Input
 2 # 1 5
 3 # 10 20
 4 # 0 0
 5 # Example Output
 6 # 6
 7 # 3
 8 
 9 while True:
10     a = []
11     for x in input().split():
12         a.append(int(x))
13     if a[0] == a[1] == 0: # 以0 0结束
14         break
15     print(sum(a))

 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

 1 # Example Input
 2 # 4 1 2 3 4
 3 # 5 1 2 3 4 5
 4 # 0
 5 # Example Output
 6 # 10
 7 # 15
 8 
 9 while True:
10     a = []
11     line = input()
12     for x in line.split():
13         a.append(int(x))
14     if a[0] == 0:
15         break
16     print(sum(a)-a[0])

 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

 1 # Example Input
 2 # 4
 3 # 1 2 3 4
 4 # 5
 5 # 1 2 3 4 5
 6 # 0
 7 # Example Output
 8 # 10
 9 # 15
10 
11 while(int(input())):
12     print(sum(int(x) for x in input().split()))

 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-

 1 # Example Input
 2 # 2
 3 # 4 1 2 3 4
 4 # 5 1 2 3 4 5
 5 # Example Output
 6 # 10
 7 # 15
 8 
 9 N = int(input())
10 while N:
11     a = []
12     line = input()
13     for x in line.split():
14         a.append(int(x))
15     print(sum(a)-a[0])
16     N -= 1


这些基础部分输入输出仅供参考、欢迎交流

 

posted on 2017-07-19 11:29  黎夜  阅读(184)  评论(0编辑  收藏  举报