python学习第三天

If Statements

##if statements做决策
temperature=35
if temperature>30:#python中缩进与C中的{}等同,属于一个block
    print("It's a hot day")
    print('It\'s a hot day') #当使用单引号且输出语句中那个含有单引号时,要使用转义字符
elif temperature>20: #(20,30]
    print("It's a nice day")
elif temperature>10: #(10,20]
    print("It's a bit cold")
else:#(-∞,10]
    print("It's very cold")

Exercise

输出如下形式:
在这里插入图片描述
要求第二行可输入大写或者小写

#exercise
Weight_input=input("Weight: ")
K_or_L=input("(K)g or (L)bs: ")
if ('L'==K_or_L)or('l'==K_or_L):
#if 'L'==K_or_L.upper():
    print("Weight in Kg: ",float(Weight_input)*0.45)
elif ('K'==K_or_L)or('k'==K_or_L):
    translator=float(Weight_input)/0.45
    print("Weight in Lbs:"+str(translator))
   # print("Weight in Lbs: ",float(Weight_input)/0.45)
else:
    print("Plase input the correct type!")

While Loops

#while loops
i=1
while i<=10:  #一直循环直到不满足条件
    print(i)
    print(i*'*')  #可以输出i个*
    i=i+1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值