当前位置: 首页 > news >正文

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


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

 

转载于:https://www.cnblogs.com/cradle-q0518/p/7204809.html

相关文章:

  • 公有属性 公有方法(原型方法) 私有属性 私有方法 特权方法 静态属性 静态方法 对象字面量创建...
  • angularJS指令
  • 头文件assert.h
  • 后台运行命令:amp;和nohup command amp; 以及关闭、查看后台任务
  • 进程间通信之-信号signal--linux内核剖析(九)
  • 入门之快速排序
  • 基于.NET CORE微服务框架 -谈谈surging的服务容错降级
  • Vue框架 周期
  • 转 JavaScript 检查(Linting)工具的比较
  • 前端知识学习——html
  • oracle中length、lengthb、substr、substrb用法小结
  • SAS笔记(5) FLAG和计数器
  • 用于检测移动设备(包括平板电脑)的轻量级PHP类
  • 170511、Spring IOC和AOP 原理彻底搞懂
  • CodeChef Forest Gathering —— 二分
  • python3.6+scrapy+mysql 爬虫实战
  • 「前端」从UglifyJSPlugin强制开启css压缩探究webpack插件运行机制
  • classpath对获取配置文件的影响
  • Elasticsearch 参考指南(升级前重新索引)
  • Hibernate最全面试题
  • HTTP中GET与POST的区别 99%的错误认识
  • Invalidate和postInvalidate的区别
  • Javascript基础之Array数组API
  • java中具有继承关系的类及其对象初始化顺序
  • React-Native - 收藏集 - 掘金
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • XML已死 ?
  • 百度小程序遇到的问题
  • 学习笔记:对象,原型和继承(1)
  • 移动端 h5开发相关内容总结(三)
  • MiKTeX could not find the script engine ‘perl.exe‘ which is required to execute ‘latexmk‘.
  • ​MySQL主从复制一致性检测
  • ​第20课 在Android Native开发中加入新的C++类
  • #基础#使用Jupyter进行Notebook的转换 .ipynb文件导出为.md文件
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (二)windows配置JDK环境
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (原+转)Ubuntu16.04软件中心闪退及wifi消失
  • (转)母版页和相对路径
  • ./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’: ./incl
  • .babyk勒索病毒解析:恶意更新如何威胁您的数据安全
  • .NET MAUI学习笔记——2.构建第一个程序_初级篇
  • .Net Remoting常用部署结构
  • .net(C#)中String.Format如何使用
  • .net6+aspose.words导出word并转pdf
  • .net项目IIS、VS 附加进程调试
  • .net之微信企业号开发(一) 所使用的环境与工具以及准备工作
  • [ C++ ] STL---string类的使用指南
  • [ CTF ]【天格】战队WriteUp- 2022年第三届“网鼎杯”网络安全大赛(青龙组)
  • [ Linux ] Linux信号概述 信号的产生
  • [383] 赎金信 js
  • [AAuto]给百宝箱增加娱乐功能
  • [AR Foundation] 人脸检测的流程
  • [c]扫雷
  • [C++]:for循环for(int num : nums)