score = input("请输入分数:")
temp = int(score)
if(90<=temp<=100):
print("A")
elif(80<=temp<90):
print("B")
elif(60<=temp<80):
print("C")
elif(temp<60):
print("D")
else:
print("输入错误")
assert断言,为假则抛出assertionError 错误,为真则忽略断言。。。
>>> assert 4 < 3
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
assert 4 < 3
AssertionError
>>> assert 4>3
>>>
========================================
for循环
>>> favourite = "lixiaohu"
>>> for i in favourite:
print(i)
l
i
x
i
a
o
h
u
>>> for i in favourite:
print(i,end=" ")
l i x i a o h u
>>>
数组循环:
>>> menmber =["小虎牙","黑夜神","白天天","白云","彩虹"]
>>> for i in menmber:
print(i,len(i))
小虎牙 3
黑夜神 3
白天天 3
白云 2
彩虹 2
>>>
=============================
range循环
>>> range(5)
range(0, 5)
>>> list(range(5))
[0, 1, 2, 3, 4]
>>> for i in range(5):
print(i)
0
1
2
3
4
>>> for i in range(2,9):
print(i)
2
3
4
5
6
7
8
>>>
range第三个参数为步进,第一个参数为起始数,第二个参数为终止数,
>>> for i in range(1,10,2):
print(i)
1
3
5
7
9
>>>
=========================
break循环:
bingo = "li"
answer = input("请输入心里话:")
while(True):
if answer == bingo:
break
answer = input("输入错误,请重新输入:")
print("终于对了。。。。哈哈哈哈。。。。")
========================================
continue循环:
for i in range(10):
if(i%2 != 0):
print(i)
continue
i +=2
print(i)
打印如下:
2
1
4
3
6
5
8
7
10
9