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条件后,触发。

错误笔记

  1. python 中一定要注意语法之前的缩进。
  2. 一个语法判断结束后面一定要加冒号。
  3. 判断 符号<= 中的等号不能写在<号的前面。
  4. 注意大小写,如true 会报错,必须True.

转载于:https://www.cnblogs.com/Dtime/p/10954488.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值