Python日记(三)

Python日记(三)

1.if结构

  • if
1
2
3
4
5
6
7
8
9
10
11
# -*- coding: utf-8 -*-
liaoyue = int(input("请给撩月打分:"))

if liaoyue >= 85:
print("不敢当不敢当")

if liaoyue < 60:
print ("你干嘛~哎呦")

if (liaoyue >= 60) and (liaoyue < 85):
print ("指定没你好果汁吃!")

  • if -else
1
2
3
4
5
6
7
# -*- coding: utf-8 -*-
liaoyue = int(input("请给撩月打分:"))

if liaoyue >= 85:
print("不敢当不敢当")
else:
print ("你干嘛~哎呦")

  • if-elif-else
1
2
3
4
5
6
7
8
9
10
11
# -*- coding: utf-8 -*-
liaoyue = int(input("请给撩月打分:"))

if liaoyue >= 90:
print("不敢当不敢当")
elif liaoyue >= 80:
print ("还行还行")
elif liaoyue >= 70:
print ("咋地,对我有意见啊")
else:
print ("你干嘛~哎呦")

2.while语句

(注:只有Python中的while循环是跟有else的,目前的其他语言是没有的)

1
2
3
4
5
6
7
# -*- coding: utf-8 -*-
i = 0
while i * i < 1000:
i +=1

print ("i = ", i)
print("i * i =", i*i)
1
2
3
4
5
6
7
# -*- coding: utf-8 -*-
i = 0
while i * i < 10:
i +=1
print (str(i) + '*' + str(i) + '=',i*i)
else:
print("over")

3.For循环语句

1
2
3
4
5
6
7
8
9
10
# -*- coding: utf-8 -*-

print ("——————字符串——————")
for item in 'liaoyue':
print (item)

print ("——————列表——————")
numbers = [21, 22, 23, 24]
for item in numbers:
print (item)
1
2
3
4
5
6
# -*- coding: utf-8 -*-

for item in range(10):
print (item)
else:
print ("over")

4.跳转语句

  • break语句
  • continue语句
  • return语句

Python日记(三)
https://one-null-pointer.github.io/2022/08/23/Python日记(三)/
Author
liaoyue
Posted on
August 23, 2022
传送口