几种常见运算符和while循环及其相关

# 1 算数运算符
# int,float=>数字类型
# print(10 + 3.1)
# print(10 / 3)[保留小数和精确值]
# print(10 // 3)[保留结果整数部分]
# print(10 % 3)[整除余数]
# print(10 ** 2)[10的平方]
# 2 赋值运算符
# 增量赋值
# age=18
# age+=1 # age=age + 1
# print(age)
 3交叉赋值
# x=11
# y=22

# temp=x
# x=y
# y=temp
# x,y=y,x
# print(x,y)
# 4链式赋值
# x=10
# y=x
# z=y

# x=y=z=10
# print(x,y,z)
#5 解压赋值
# 1. 列表的解压赋值
l=['egon',18,'male',33333]
# a=l[0]
# b=l[1]
# c=l[2]
# d=l[3]
# 6. 字典的解压赋值
# dic={'aaa':1,'bbb':2,'ccc':3}
# x,y,z=dic
# print(x,y,z)
# 7 逻辑运算符
# and: 左右两个条件必须同时成立,最终结果才为True
# print(10 < 3 and 3 == 3)

# or: 左右两个条件只要有一个成立,最终结果就为True
# print(10 < 3 or 3 == 3)
# print(10 < 3 or 3 < 3)

# not:将紧跟其后的条件结果取反
# print(not 10 > 3)
# print(not 10 < 3 or 3 < 3)

# res=(10 > 3 and 3 == 1) or ((4 < 3 and True) or (not 1 > 2 or 3 > 2))

# print(res)

8比较运算符:

==和 !=(不等于)

9.if条件条件判断语法;

语法一;

#gender='female'
# age=18
# is_beautiful=True
#
# if gender == 'female' and age > 16 and age < 20 and is_beautiful:
#     print('开始表白。。。。')

语法二;

# gender='female'
# age=26
# is_beautiful=True
#
# if gender == 'female' and age > 16 and age < 20 and is_beautiful:
#     print('开始表白。。。。')
# else:
#     print('阿姨好')

语法三:

# gender='female'
# age=18
# is_beautiful=True
# is_successfull=True
#
# if gender == 'female' and age > 16 and age < 20 and is_beautiful:
#     print('开始表白。。。。')
#     if is_successfull:
#         print('在一起,,,')
#     else:
#         print('逗你玩呢。。。')

语法四:

'''
如果:成绩>=90,那么:优秀

如果成绩>=80且<90,那么:良好

如果成绩>=70且<80,那么:普通

其他情况:很差
'''

score=input('your score: ')
score=int(score)

if score >= 90:
    print('优秀')
elif score >= 80:
    print('良好')
elif score >= 70:
    print('普通')
else:
    print('很差')

流程控制之while循环;

#循环就是重复做某件事
# 语法:
# n=1
# while n < 10:
#     print(n)
#     n+=1

# name='egon'
# pwd='123'
#
# tag=True
# while tag:
#     inp_name=input('your name: ')
#     inp_pwd=input('your password: ')
#     if inp_name == name and inp_pwd == pwd:
#         print('login successfull')
#         tag=False
#     else:
#         print('name or password error')
# while+break:终止本层循环
name='egon'
pwd='123'

while True:
    inp_name=input('your name: ')
    inp_pwd=input('your password: ')
    if inp_name == name and inp_pwd == pwd:
        print('login successfull')
        break
    else:
        print('name or password error')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值