duyixian1234

# 前言

``````"""Simple Console Program With Data Input And Output."""
import sys
import io

def read_int():
"""Read a seris of numbers."""
return list(map(int, sys.stdin.readline().split()))

def test_read_int():
"""Test the read_int function"""
test_file = io.StringIO("1 2 3\n")
sys.stdin = test_file
assert read_int() == [1, 2, 3], "read_int error"

def read_float():
"""Read a seris of float numbers."""
return list(map(float, sys.stdin.readline().split()))

def test_read_float():
"""Test the read_float function"""
test_file = io.StringIO("1 2 3\n")
sys.stdin = test_file
assert read_float() == [1.0, 2.0, 3.0], "read_float error"

def read_word():
"""Read a seris of string."""
return list(map(str, sys.stdin.readline().split()))

def test_read_word():
"""Test the read_word function"""
test_file = io.StringIO("1 2 3\n")
sys.stdin = test_file
assert read_word() == ["1", "2", "3"], "read_word error"

def combine_with(seq, sep=' ', num=None):
"""Combine list enum with a character and return the string object"""
res = sep.join(list(map(str, seq)))
if num is not None:
res = str(seq[0])
for element in range(1, len(seq)):
res += sep + \
str(seq[element]) if element % num != 0 else '\n' + \
str(seq[element])
return res

def test_combile_with():
"""Test the combile_with function."""
assert combine_with([1, 2, 3, 4, 5], '*', 2) == """1*2
3*4
5""", "combine_with error."

def main():
"""The main function."""
pass

if __name__ == '__main__':
sys.exit(int(main() or 0))

``````

# VS Code代码片段

• 文件->首选项->用户代码片段，选择Python

• 编辑"python.json"文件如以下内容
``````{
/*
// Place your snippets for Python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// \$1, \$2 for tab stops, \${id} and \${id:label} and \${1:label} for variables. Variables with the same id are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('\$1');",
"\$2"
],
"description": "Log output to console"
}
*/
"Simple Console Program With Data Input And Output": {
"prefix": "simple",
"body": ["\"\"\"Simple Console Program With Data Input And Output.\"\"\"\nimport sys\n\ndef read_int():\n    \"\"\"Read a seris of numbers.\"\"\"\n    return list(map(int, sys.stdin.readline().split()))\n\n\ndef read_float():\n    \"\"\"Read a seris of float numbers.\"\"\"\n    return list(map(float, sys.stdin.readline().split()))\n\n\ndef read_word():\n    \"\"\"Read a seris of string.\"\"\"\n    return list(map(str, sys.stdin.readline().split()))\n\n\ndef combine_with(seq, sep=' ', num=None):\n    \"\"\"Combine list enum with a character and return the string object\"\"\"\n    res = sep.join(list(map(str, seq)))\n    if num is not None:\n        res = str(seq[0])\n        for element in range(1, len(seq)):\n            res += sep + str(seq[element]) if element % num != 0 else '\\n' + str(seq[element])\n    return res\n\n\ndef main():\n    \"\"\"The main function.\"\"\"\n    pass\n\n\nif __name__ == '__main__':\n    sys.exit(int(main() or 0))\n"
],
"description": "Simple Console Program With Data Input And Output"
}
}```
然后再编写Python代码的时候，键入"simple"就可以自动输入以上模板。

![](https://static.oschina.net/uploads/img/201608/04182804_9GZn.png "在这里输入图片标题")
# 总结

``````

© 著作权归作者所有

### duyixian1234

flynewton
2010/11/16
0
0

OSCHINA 本期高手问答(2018 年 12 月 11 日 — 12 月 17 日)我们请来了@zjgogogo 张洁为大家解答关于算法方面的问题。 张洁，计算机专业科班出身，获博士学位，《你也能看懂的Python算法书》...

2018/12/10
0
10

AI这个词相信大家都非常熟悉，近几年来人工智能圈子格外热闹，光是AlphoGo就让大家对它刮目相看。今天小天就来跟大家唠一唠如何进军人工智能的第一步——机器学习。 在机器学习领域，Python已...

ufv59to8
2018/05/12
0
0

（一）说明 1、记录自己面试测试工程师时遇到的一些编程题（python）。 2、回顾下面试的过程，做个总结。 （二）题目 1、输入：JSON {"a":"aa","b":"bb","c":{"d":"dd","e":"ee"}} 输出：字典......

free赖权华
2018/08/03
0
0

super0555
2013/09/14
4.1K
5

41分钟前
1
0
MySQL mysqldump数据导出详解

MySQL mysqldump数据导出详解 2016-04-07 11:14 by pursuer.chen, 114348 阅读, 0 评论, 收藏, 编辑 介绍 在日常维护工作当中经常会需要对数据进行导出操作，而mysqldump是导出数据过程中使用...

linjin200
41分钟前
0
0
Lucene 检索时的步骤

kdy1994
41分钟前
2
0
Gradle Implementation vs API configuration

SuShine
45分钟前
2
0
pdf安卓手机适配以及ie的兼容 以及隐藏掉下载打印按钮的方式

51分钟前
1
0