-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonTalk01.tex
206 lines (192 loc) · 4.42 KB
/
PythonTalk01.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
\input{LatexConfig.tex}
\begin{document}
\PreFirstFrame
\begin{frame} [fragile]
\centerline{\fontsize{42}{42}\selectfont Python Talk 1}
\end{frame}
\PostFirstFrame
\begin{frame}
\frametitle{Python 是什么?}
\linespread{2}
\begin{itemize}
\item Python 是一个多用途的高级语言
\item Python 可以用简单的代码完成复杂的工作
\item 我们使用 Python3.7 进行编程
\item 推荐使用 Python3 和更高版本
\end{itemize}
\end{frame}
\begin{frame} [fragile]
\frametitle{2的999次方最后两位是多少?}
\begin{columns}[T]
\begin{column}[T]{.2\textwidth}
\begin{itemize}
\item 计算器
\begin{lstlisting}[style=pythonstyle, gobble=12]
2^999
\end{lstlisting}
(不精确)
\end{itemize}
\end{column}
\begin{column}[T]{.8\textwidth}
\begin{itemize}
\item Python 3
\begin{lstlisting}[style=pythonstyle, gobble=12]
print(2 ** 999 % 100)
\end{lstlisting}
\item C
\begin{lstlisting}[style=cstyle, gobble=12]
#include "stdio.h"
int main(void) {
int last = 1;
for(int i = 0; i < 999; i += 1){
last *= 2;
last %= 100;
}
printf("%d\n", last);
return 0;
}
\end{lstlisting}
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame} [fragile]
\frametitle{基本计算}
\begin{itemize}
\item Python可以轻松完成基本的数学计算
\item 像做数学题一样输入方程即可!
\item 运算符
\begin{lstlisting}[style=pythonstyle, gobble=4, texcl]
+ # 加
- # 减
* # 乘
/ # 除
** # 乘方
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame} [fragile]
\frametitle{计算以下数值}
\begin{lstlisting}[style=pythonstyle, gobble=4,
basicstyle=\linespread{2}\ttfamily]
1234 + 5678 - 2836
3856 * 9274 * 576
2957 / 3857
7 的 123 次方
\end{lstlisting}
\end{frame}
\begin{frame} [fragile]
\frametitle{Tips}
\begin{itemize}
\item 得到上次的结果
\begin{lstlisting}[style=pythonstyle, gobble=4]
3 + 7
_ * 2
\end{lstlisting}
\item 这个符号是什么?
\begin{lstlisting}[style=pythonstyle, gobble=4]
3 // 5
3 / 5
\end{lstlisting}
\item 求余数
\begin{lstlisting}[style=pythonstyle, gobble=4, texcl]
8 % 5 # 得到8÷5的余数
# 负数会怎样?
\end{lstlisting}
\item 将结果保存
\begin{lstlisting}[style=pythonstyle, gobble=4]
5 + 8
a = _
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame} [fragile]
\frametitle{数值比较}
\begin{itemize}
\item 使用这些运算符
\begin{lstlisting}[style=pythonstyle, gobble=4, texcl,
basicstyle=\linespread{1.5}\ttfamily]
> # 大于
< # 小于
== # 等于,注意不是 =
!= # 不等于
>= # 大于等于
<= # 小于等于
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame} [fragile]
\frametitle{逻辑运算}
\begin{itemize}
\item 数值比较的结果是真假值,如 \texttt{2 < 3} 为真;\texttt{4 < 3} 为假
\begin{lstlisting}[style=pythonstyle, gobble=4, texcl,
basicstyle=\linespread{1.5}\ttfamily]
True # 真
False # 假
and # 且 / 与
or # 或
not # 非
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame} [fragile]
\frametitle{试试看}
\begin{itemize}
\item 这些变量是真是假?
\begin{lstlisting}[style=pythonstyle, gobble=4]
0
1
'HCC'
3.14
\end{lstlisting}
\item 判断方法
\begin{lstlisting}[style=pythonstyle, gobble=4, texcl]
a = 0
a == True # 不对?
bool(a) # 正确
# 继续尝试 a = 1 等
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame} [fragile]
\frametitle{Python类型}
\begin{columns}[T]
\begin{column}[T]{.6\textwidth}
\begin{itemize}
\item 常见基本类型
\begin{lstlisting}[style=pythonstyle, gobble=12, texcl]
int # 整数
str # 字符串
float # 浮点数
bool # 真假值 / 布尔值
\end{lstlisting}
\item 如何查看一个变量的类型
\begin{lstlisting}[style=pythonstyle, gobble=12, texcl]
type(a)
\end{lstlisting}
\item 尝试
\begin{lstlisting}[style=pythonstyle, gobble=12, texcl]
int(3.4)
help(int)
\end{lstlisting}
\end{itemize}
\end{column}
\begin{column}[T]{.4\textwidth}
\begin{itemize}
\item 判断以下变量的类型
\begin{lstlisting}[style=pythonstyle, gobble=12, texcl]
1
'HCC'
3.14
True
\end{lstlisting}
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\PreLastFrame
\begin{frame}
\centerline{\fontsize{32}{32}\selectfont 感谢参加此次活动}
\end{frame}
\newpage
\end{document}