学习第二天(条件判断语句,判断变量,三目算法,循环)

1.条件判断语句

if;condition

#一、单一情况
#1.if后面填的不是True就是False
    is_drink = True
    cond = is_drik is True
        print(cond)
    if cond:
        print("喝酒不开车")

#2.and;两端条件成立则整体成立
account = "zhangsan"
psw = "123"
cond1 = account == "zhangsan"
cond2 = psw =="123"
cond3 = cond1 and cond2
     print(cond1,cond2,cond3)
if conds:
     print("登录成功")

#3.or;两端有一个则整体成立
account ="zhangsan
is_super_user = true
cond1 = account == "zhangsan"
cond2 = is_supeer_user  is True
cond3 = cond1 or cond2
     print(cond1,cond2,cond3)
if cond3:
     print("没问题")

#4.not;不是/否  条件不成立,则整体成立
is_super_user = True
cond1 = is_super_user  is True
cond2 = not cond1
     print(cond1,cond2)
if cond2:
     print("权限不足")

#二、二选一
ticket > 4
if ticket >3:
   print("购买成功")
else:
   print("购买失败")

#多选一
alcohol =25
if 0<= alcohol <20:
      print("可以开车")
elif 20<=  alcohol <80:
      print("饮酒驾驶")
else:
      print("醉酒驾驶")

ticket = 4
if ticket>3
     print("购买成功")
else:
     print("购买失败")

#三、多选一
alcohol = 25
if 0<= alcohol <20:

    

2.判断变量是否为空

null_str = ""

     if not null_str:

     print("空字符串")


null_dict ={}
#空字典

null_list =[]
#空列表

null_tuple=()
#空元组

 

3.三目运算符特点

#1.如果逻辑中只有一句话,则可以考虑,三目运算

#2.逻辑超过一句话,会很麻烦

除/    整除//   余数%

4.range 的三个用法

(start=0,end,step=!)

5.for和while应用场景

1.已知重复次数  用for 已知总次数

2.未知重复次数   用while未知总页数

6.for,while循环基本格式(in可迭代对象)(while do)

for  a in 'abcd'

    print(a)

 

 

total = 0

num=1

while num <=11:

    total += num

    pringt(total)

可迭代对象=字符串+列表+字典+元组+文件句柄

7.随机数

from  dandom import    randint

   sys_num = randint(50,51)

   print(sys_num)

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值