-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa60b6f
commit 1bfb947
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**题目:**输入三个整数x,y,z,请把这三个数由小到大输出。\n", | ||
"\n", | ||
"**程序分析:**我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。\n", | ||
"\n", | ||
"程序源代码:\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"integer:\n", | ||
"2\n", | ||
"integer:\n", | ||
"3\n", | ||
"integer:\n", | ||
"4\n", | ||
"[2, 3, 4]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#!/usr/bin/python\n", | ||
"# -*- coding: UTF-8 -*-\n", | ||
" \n", | ||
"l = []\n", | ||
"for i in range(3):\n", | ||
" x = int(input('integer:\\n'))\n", | ||
" l.append(x)\n", | ||
"l.sort()\n", | ||
"print (l)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**题目**:模仿静态变量(static)另一案例。\n", | ||
"\n", | ||
"**程序分析**:演示一个python作用域使用方法\n", | ||
"\n", | ||
"程序源代码:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"The num = 3\n", | ||
"nNum = 2\n", | ||
"The num = 4\n", | ||
"nNum = 3\n", | ||
"The num = 5\n", | ||
"nNum = 4\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#!/usr/bin/python\n", | ||
"# -*- coding: UTF-8 -*-\n", | ||
"\n", | ||
"class Num:\n", | ||
" nNum = 1\n", | ||
" def inc(self):\n", | ||
" self.nNum += 1\n", | ||
" print ('nNum = %d' % self.nNum)\n", | ||
"\n", | ||
"if __name__ == '__main__':\n", | ||
" nNum = 2\n", | ||
" inst = Num()\n", | ||
" for i in range(3):\n", | ||
" nNum += 1\n", | ||
" print ('The num = %d' % nNum)\n", | ||
" inst.inc()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |