if和else和elif
在输入中判断对错时会需要if else 以及 elif
注:在输入if else elif 时要将下一排的print向后推4格
1.成绩的参考:
首先我们在进入文件后先要将把你所需要的转化为int的形式比如我将score转化为int的形式
score=int(input('请输入分数')
然后我会再用if和elif来表示如
if score >= 100: print("厉害呀") elif score >= 90: print("很好") elif score>=80: print("不错") elif score>=70: print('还行') elif score>=60: print("恭喜你及格了") elif score<60: print("准备补考吧")
这就是成绩的输入。
2.用户的输入
在用户的输入时我们还会用到else的比如当用户名或者是密码错误时我们就会使用到else
username=input("请输入用户名:") password=input("请输入密码:") code="qwer" your_code=input("请输入验证码") if your_code==code: if username=="zhuhaoheng" and password=="123": print("登录成功") else: print("滚出去") else: print("验证码错误")
注;在使用 if else elif 时下一排的print要向后推4格