1.if 语句
if…else 语句
score = 75
if score >= 60:
print('及格')
else:
print('不及格')
if…elif…else
if score >= 90:
print('优秀')
elif score >= 60:
print('及格')
else:
print('不及格')
2. while 循环
1.形式
a, b = 0,10
while a < b:
print(a)
a += 1
2.关键字
break:跳出循环
while True:
name = input('请输入您的姓名:')
if name == 'stop':
break
age = input('请输入您的年龄')
print('您好:{},您的年龄是:{}'.format(name,age))
continue:满足某条件时,跳到下一次循环
x = 10
while x:
x -= 1
if x % 2 != 0: # 判断是否为奇数
continue # 跳出本次循环
print(x)
3.for 循环语句
l = [1,2,3]
for x in l:
print(x)
emp = {'name':'Tom','department':'tech',
'job':'development','saary':'8000'}
for key in emp.keys(): # 循环字典表中的键
print('{}--{}'.format(key,emp.get(key)))