python while if_python基础语法if while

IF语句

第一种:

if 5<4 :

print(66)

else :

print(999)

注:如果不满足条件执行下面。

第二种:

if 4>5 :

print("我请你喝酒")

print("喝什么酒")

注:无论是否满足条件,都执行下面。

"""

#多选:

num = input("请输入您猜的数字")

if num == "1":

print("恭喜您获得擦屁股纸一卷")

elif num =="2":

print("恭喜您获得腾讯视频VIP一个月试用资格")

elif num =="3":

print("恭喜您获得CF会员一个月试用资格")

else :

print("很遗憾。。。。。。。。")

分数转换:

score = int(input("输入分数"))

if 100>=score>90:

print("A")

elif 90>=score>80:

print("B")

elif 80>=score>60:

print("C")

elif 60>=score>0:

print("D")

else :print("输入分数应在0-100之间")

嵌套if语句:

name = input("请输入您的姓名")

age = input("请输入您的年龄")

if name == "张三":

if age == "19":

print("年轻人")

else:print("输入错误")

else :print("输入错误")

while语句

1-100求和:

count =1

sum =0

while count <= 100:

sum =sum+count

count=count+1

print(sum)

print1-100:

count =1

flag = True       (标志位)

while flag:

print(count)

count =count+1

if count>100 :

flag = False

Break终止while循环:

count=1

while True:

print(count)

count=count+1

if count>100:break

continue,and用法:

count=0

while count<=100:

count +=1

if count>5 and count<95:

continue

print("loop",count)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值