Python:逻辑运算符and比较运算符以及布尔输入

# bool输入 将空字符串作为False 
is_hot = bool(input("t or f"))

运算符

# 逻辑运算符
# &&  and
# ||  or
# !   not 但是要表达多个之间,需要用上面的两个词作为连接词
has_high_income = False
has_good_credit = True
if has_good_credit or has_high_income:
    print("get a little loan ")
if has_good_credit and has_high_income:
    print("get loan")
else:
    print("not get loan")
if has_good_credit and not has_high_income:
    print("say no")
if not has_high_income:
    print("so poverty")


# 比较运算符 >=    <=     >   <    ==   !=
temperature = 30
if temperature == 30:
    print("It's hot day")
else:
    print("It's not hot day")

test 1 ,体重转换器

# 输入kg转换为bs bs转换kg
user_weight = input("Weight : ")
option = input("(L)bs or (K)g: ")
# if option == 'L' or option == 'l':
if option.upper()=='L':
    print(f"you are {float(user_weight) * 0.45} kg")
elif option.upper() == 'K':
    print(f"you are {float(user_weight) / 0.45} pounds")
else:
    print("your option had error! ")
# index的正负应用
name = "Jennifer"
print(name[1:-1])

test2:简单比较运算符应用

name = input("What's your name? ")
length = len(name)
if length < 3:
    print("the name must be at least 3 characters")
elif length > 50:
    print("the name can be a maximum of 50 characters")
else:
    print(f'name: {name} looks good!')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值