From a1a4637bce430c83fa1ed1d1a34148876e1cd110 Mon Sep 17 00:00:00 2001 From: hrj_mac Date: Sun, 20 Aug 2023 21:10:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E7=9A=84=E8=AF=AD=E6=B3=95=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\344\273\266\345\210\244\346\226\255.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "\346\235\241\344\273\266\345\210\244\346\226\255.py" diff --git "a/\346\235\241\344\273\266\345\210\244\346\226\255.py" "b/\346\235\241\344\273\266\345\210\244\346\226\255.py" new file mode 100644 index 0000000..1115ccf --- /dev/null +++ "b/\346\235\241\344\273\266\345\210\244\346\226\255.py" @@ -0,0 +1,23 @@ +''' +1. 根据Python的缩进规则,如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做。 + +''' + +# 年龄判断 +age = 16 +if age >= 18: + print('You age is %d' % age) + print('Adult') +else: + print('You age is %d' % age) + print('Teenager') + +# 分支语句判断 +age = input('Please enter your name: ') +age = int(age) +if age < 2: + print('Baby') +elif age < 18: + print('Teenager') +elif age < 70: + print('Labor') \ No newline at end of file -- Gitee From b8332e3663206bdf83cdb6659f31732b137279b9 Mon Sep 17 00:00:00 2001 From: hrj_mac Date: Mon, 21 Aug 2023 22:19:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E8=AF=AD=E6=B3=95=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\345\276\252\347\216\257.py" | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "\345\276\252\347\216\257.py" diff --git "a/\345\276\252\347\216\257.py" "b/\345\276\252\347\216\257.py" new file mode 100644 index 0000000..bdea07d --- /dev/null +++ "b/\345\276\252\347\216\257.py" @@ -0,0 +1,47 @@ +''' +1. 循环的目的:使得计算机可以进行大量重复的运算 +2. python中有两种循环,第一种是for A in B循环,依次把list或者tuple中的元素迭代出来,把B中的元素依次代入A中。 +3. 第二种循环是while循环,只要条件满足,就不断循环,条件不满足时退出循环。 +4. break语句可以在循环过程中直接退出循环,而continue语句可以提前结束本轮循环,并直接开始下一轮循环。 + 这两个语句通常都必须配合if语句使用。 +''' + +# for 循环 +# for x in ...循环就是把每个元素代入变量x,然后执行缩进块的语句。 +names = ['Bob', 'Helen', 'Black'] +for name in names: + print(name) + +# 计算1-10整数的和 +sum = 0 +for x in [1,2,3,4,5,6,7,8,9,10]: + sum = x+sum +print(sum) + +# 计算1-100整数的和, range()函数可以用来生成小于101的整数 +sum = 0 +for x in list(range(101)): + sum = x + sum +print(sum) + +# while循环 +sum = 0 +n = 99 +while n > 0: + sum = sum + n + n = n - 2 +print(sum) + +# continue +for i in tuple(range(10)): + if i % 2 == 0: # 利用continue语句跳过偶数 + continue + print(i) + +# break +n = 0 +while n < 10: + print(n) + n = n + 1 + if n > 5: + break \ No newline at end of file -- Gitee