牛客网python入门篇~条件语句练习

NP43 判断布尔值

num=int(input())
if num==1:
    print("Hello World!")
elif num==0:
    print("Erros!")

NP44 判断列表是否为空

my_list=[]
if len(my_list)==0:
    print("my_list is empty!")
else:
    print("my_list is not empty!")

NP45 禁止重复注册

current_users=["Niuniu","Niumei","GURR","LOLO"]
new_users=["GurR","Niu Ke Le","LoLo","Tuo Rui Chi"]
current_users_l=[user.lower() for user in current_users]
for user in new_users:
    if user.lower() in current_users_l:
        print(f"The user name {user} has already been registered! Please change it and try again!")
    else:   
        print(f"Congratulations, the user name {user} is available!")

NP46 菜品的价格

name=input()
if name=="pizza":
    print(10)
elif name=="rice":
    print(2)
elif name=="yogurt":
    print(5)
else:
    print(8)

NP47 牛牛的绩点

my_dict={"A":4.0,"B":3.0,"C":2.0,"D":1.0,"F":0}

count1=0
count2=0
while True:
    course=input()
    if course=="False":
        break
    else:
        num=int(input())
        count1+=num*my_dict[course]
        count2+=num
print("%.2f" %(count1/count2))

NP48 验证登录名与密码

my_dict={"name":"admis","passwd":"Nowcoder666"}
username=input()
password=input()

if username==my_dict["name"] and password==my_dict["passwd"]:
    print("Welcome!")
else:
    print("user id or password is not correct!")

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值