python语法&错误笔记-day01
语法
-
python语法中,由上往下执行,一个流程中有一个条件满足后会停止执行下面的流程。
-
一定要注意各语名之前的层级缩进。
-
if...elif...else
content = '''欢迎咨询10086!
1、话费查询
2、流量查询
3、业务办理
4、人工服务'''
print(content)
CustomerInput = input('请输入您要办理的业务编号:')
CustomerInput = int(CustomerInput)
if CustomerInput == 1:
print('话费查询')
elif CustomerInput == 2:
print('流量查询')
elif CustomerInput == 3:
content_business = """1、手机业务
2、固话业务
3、宽带业务"""
print(content_business)
business = input('请选择你要办理的业务:')
business = int(business)
if business == 1: # 嵌套
print('手机业务')
elif business == 2:
print('固话业务')
elif business == 3:
print('宽带业务')
else:
print('请选择正确的编号!')
elif CustomerInput == 4:
print('人工服务')
else:
print('请输入正确编号')
- print('')
print("这个显示输出")
# 三个引号,可以换行
content = '''床前明月光,
疑是地上霜。'''
print(content)
- while
#循环嵌套
while True:
print('这是第一个循环')
while True:
print('这是第二个循环,需要下面加break,才能中止当前循环,进行第一个循环。')
break
break
#打印1 2 3 4 5 6 8 9 10
count = 1
while count <= 10:
if count != 7:
print(count)
count = count + 1
print('结束')
'''循环打印'''
count = 0
while count >= 0 and count <= 99:
count = count + 1
print(count)
#或者
count = 1
while count <= 100:
print(count)
count = count + 1
- break #中止当前循环
#通过break实现1-10打印
count = 1
while True: #如果循环为真
print(count)
if count == 10:
break #如果count等于10则中止当前循环。
count = count + 1
print("结束")
- continue #本次循环如果遇到continue 则不在继续往下执行,返回
count = 1
while count <=10:
if count == 7:
count = count + 1 #给count 赋值加1,使其不等于1,方便跳出
continue # 返回循环
print(count)
count = count + 1
- while .... else #在不满足while条件后,触发。
错误笔记
- python 中一定要注意语法之前的缩进。
- 一个语法判断结束后面一定要加冒号。
:
- 判断 符号<= 中的等号不能写在<号的前面。
- 注意大小写,如true 会报错,必须True.