File tree Expand file tree Collapse file tree 4 files changed +177
-0
lines changed
Expand file tree Collapse file tree 4 files changed +177
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ 练习1:华氏温度转摄氏温度
3+ 公式:F = 1.8C + 32
4+ """
5+
6+ f = float (input ("请输入华氏温度:" ))
7+ c = (f - 32 ) / 1.8
8+ print ("%.1f 华氏度 = %.1f 摄氏度" % (f , c ))
Original file line number Diff line number Diff line change 1+ """
2+ 练习2:输入圆的半径计算计算周长和面积
3+ 周长公式:2*pi*r
4+ 面积公式:pi*r*r
5+ """
6+
7+ import math
8+
9+ r = float (input ("请输入圆的半径:" ))
10+ perimeter = math .pi * 2 * r
11+ area = math .pi * r * r
12+
13+ print ("周长 = %.1f" % perimeter )
14+ print ("面积 = %.1f" % area )
Original file line number Diff line number Diff line change 1+ """
2+ 输入年份 如果是闰年输出 True 否则输出 False
3+ 判断是否为闰年:
4+ 1. 普通闰年:能被4整除但不能被100整除的年份为普通闰年
5+ 2. 世纪闰年:能被400整除的为世纪闰年
6+
7+ Version: 1.0.0
8+ Author: Jalan
9+ """
10+
11+ year = int (input ("请输入年份:" ))
12+
13+ is_leap = (year % 4 == 0 and year % 100 != 0 ) or year % 400 == 0
14+
15+ print (is_leap )
Original file line number Diff line number Diff line change 1+ # Day02 - 语言元素
2+
3+ ## 指令和程序
4+
5+ 计算机硬件系统的五大部件:
6+
7+ - 运算器
8+ - 控制器
9+ - 存储器
10+ - 输入设备
11+ - 输出设备
12+
13+ 运算器 + 控制器 = 中央处理器(CPU)
14+
15+ 任务:复习冯·诺依曼结构。
16+
17+ ## 变量和类型
18+
19+ 1 . 整型
20+ - 可以处理任意大小的整数(不存在溢出情况)
21+ - 支持二进制(如` 0b100 ` ,换算成十进制是4)、八进制(如` 0o100 ` ,换算成十进制是64)、十进制(` 100 ` )和十六进制(` 0x100 ` ,换算成十进制是256)的表示法
22+ 2 . 浮点型
23+ 3 . 字符串型
24+ 4 . 布尔型:` True ` / ` False `
25+ 5 . 复数型
26+
27+ ## 变量命名
28+
29+ PER 8 要求:
30+
31+ - 用小写字母拼写,多个单词用下划线连接
32+ - 受保护的实例属性用单个下划线开头
33+ - 私有的实例属性用两个下划线开头
34+
35+ ## 变量强制转换
36+
37+ - ` int() ` :将一个数值或字符串转换成整数,可以指定进制
38+ - ` float() ` :将一个字符串转换成浮点数
39+ - ` str() ` :将指定的对象转换成字符串形式,可以指定编码
40+ - ` chr() ` :将整数转换成该编码对应的字符串(一个字符)
41+ - ` ord() ` :将字符串(一个字符)转换成对应的编码(整数)
42+
43+ ----
44+
45+ ## 练习
46+
47+ ### 练习1:华氏温度转摄氏温度
48+
49+ ``` python
50+ """
51+ 练习1:华氏温度转摄氏温度
52+ 公式:F = 1.8C + 32
53+
54+ Version: 1.0
55+ Author: Jalan
56+ """
57+
58+ f = float (input (" 请输入华氏温度:" ))
59+ c = (f - 32 ) / 1.8
60+ print (" %.1f 华氏度 = %.1f 摄氏度" % (f, c))
61+ ```
62+
63+ 运行结果如下:
64+
65+ ``` zsh
66+ ➜ python-100-practice git:(master) ✗ /usr/local/opt/python/bin/python3.7 /Users/jalan/www/own/python-100-practice/day02/code/practice.py
67+ 请输入华氏温度:100
68+ 100.0 华氏度 = 37.8 摄氏度
69+ ```
70+
71+ 知识点:
72+
73+ - ` input() ` 接收终端参数
74+ - ` float() ` 强制类型转换
75+ - ` print() `
76+ - 使用 ` %.1f ` 格式化数据为小数点后一位
77+ - ` print("..." % (a, b)) ` 格式
78+
79+ ### 练习2:输入圆的半径计算计算周长和面积
80+
81+ ``` python
82+ """
83+ 练习2:输入圆的半径计算计算周长和面积
84+ 周长公式:2*pi*r
85+ 面积公式:pi*r*r
86+
87+ Version: 1.0.0
88+ Author: Jalan
89+ """
90+
91+ import math
92+
93+ r = float (input (" 请输入圆的半径:" ))
94+ perimeter = math.pi * 2 * r
95+ area = math.pi * r * r
96+
97+ print (" 周长 = %.1f " % perimeter)
98+ print (" 面积 = %.1f " % area)
99+ ```
100+
101+ 运行结果如下:
102+
103+ ``` zsh
104+ ➜ python-100-practice git:(master) ✗ /usr/local/opt/python/bin/python3.7 /Users/jalan/www/own/python-100-practice/day02/code/practice2.py
105+ 请输入圆的半径:10
106+ 周长 = 62.8
107+ 面积 = 314.2
108+ ```
109+
110+ 知识点:
111+
112+ - 圆周率:` math.pi `
113+
114+ ### 练习3:输入年份判断是不是闰年
115+
116+ ``` python
117+ """
118+ 输入年份 如果是闰年输出 True 否则输出 False
119+ 判断是否为闰年:
120+ 1. 普通闰年:能被4整除但不能被100整除的年份为普通闰年
121+ 2. 世纪闰年:能被400整除的为世纪闰年
122+
123+ Version: 1.0.0
124+ Author: Jalan
125+ """
126+
127+ year = int (input (" 请输入年份:" ))
128+
129+ is_leap = (year % 4 == 0 and year % 100 != 0 ) or year % 400 == 0
130+
131+ print (is_leap)
132+ ```
133+
134+ 运行结果:
135+
136+ ``` zsh
137+ ➜ python-100-practice git:(master) ✗ /usr/local/opt/python/bin/python3.7 /Users/jalan/www/own/python-100-practice/day02/code/practice3.py
138+ 请输入年份:2008
139+ True
140+ ```
You can’t perform that action at this time.
0 commit comments