#7测试
#7.1
my_number = 25
if my_number <20:
print("Under < 20:")
else:
print("20 or over")
#7.3 检测一个数是否大于30但小于等于40
number = float(input("输入一个数字!"))
if number > 30 and number <= 40:
print("这个数",number,"大于30但小于等于40")
else:
print("其它数!")
7.4 检测输入的Q是否大小写
letter = input("请输入大写Q或者小写q:")
if letter =="Q":
print("输入的字母是大写Q.")
else:
print("输入的字母是小写q.")
#7动手试一试
#7.1 一商家降价促销 10元以内给%10折扣,大于10 则给%20折扣
price = float(input("询问下商品价格:"))
if price <= 10:
print("商品打10%折扣,价格为",price*(1-0.1))
else:
print("商品打20%折扣,价格为",price*(1-0.2))
#7.2
sex = input("请问你的性别是男还是女:")
if sex == "男":
print("你不能参加球队.")
else:
age =float(input("请问你的年龄:"))
if age >= 10 and age <= 12:
print ("You can jion us.")
else:
print("Sorry,You can't jion us.")
#7.3加油问题
size = float(input("请问你的油箱多大尺寸?"))
full = float(input("你的油箱有多满百分比?"))
kmper = float(input("汽油每升可以跑多少千米"))
kmgo = (size-5)*full/100*kmper #5升为缓冲区,以防油表不准
print("You can go another",kmgo,"km.")
print("The next gas station is 200 km away.")
if kmgo >200 :
print("You can wait for the next station!")
else:
print("Get gas now!")
7.4 建立一个程序,判断用户输入密码才能进入这个程序。我用7.2的例子来进行这个游戏。
import easygui
password = easygui.enterbox("请输入你的密码:")
if password == "password":
easygui.msgbox("You can play this game!")
sex = input("请问你的性别是男还是女:")
if sex == "男":
print("你不能参加球队.")
else:
age =float(input("请问你的年龄:"))
if age >= 10 and age <= 12:
print ("You can jion us.")
else:
print("Sorry,You can't jion us.")
else:
easygui.msgbox("You can't paly the game!")
#7.1
my_number = 25
if my_number <20:
print("Under < 20:")
else:
print("20 or over")
#7.3 检测一个数是否大于30但小于等于40
number = float(input("输入一个数字!"))
if number > 30 and number <= 40:
print("这个数",number,"大于30但小于等于40")
else:
print("其它数!")
7.4 检测输入的Q是否大小写
letter = input("请输入大写Q或者小写q:")
if letter =="Q":
print("输入的字母是大写Q.")
else:
print("输入的字母是小写q.")
#7动手试一试
#7.1 一商家降价促销 10元以内给%10折扣,大于10 则给%20折扣
price = float(input("询问下商品价格:"))
if price <= 10:
print("商品打10%折扣,价格为",price*(1-0.1))
else:
print("商品打20%折扣,价格为",price*(1-0.2))
#7.2
sex = input("请问你的性别是男还是女:")
if sex == "男":
print("你不能参加球队.")
else:
age =float(input("请问你的年龄:"))
if age >= 10 and age <= 12:
print ("You can jion us.")
else:
print("Sorry,You can't jion us.")
#7.3加油问题
size = float(input("请问你的油箱多大尺寸?"))
full = float(input("你的油箱有多满百分比?"))
kmper = float(input("汽油每升可以跑多少千米"))
kmgo = (size-5)*full/100*kmper #5升为缓冲区,以防油表不准
print("You can go another",kmgo,"km.")
print("The next gas station is 200 km away.")
if kmgo >200 :
print("You can wait for the next station!")
else:
print("Get gas now!")
7.4 建立一个程序,判断用户输入密码才能进入这个程序。我用7.2的例子来进行这个游戏。
import easygui
password = easygui.enterbox("请输入你的密码:")
if password == "password":
easygui.msgbox("You can play this game!")
sex = input("请问你的性别是男还是女:")
if sex == "男":
print("你不能参加球队.")
else:
age =float(input("请问你的年龄:"))
if age >= 10 and age <= 12:
print ("You can jion us.")
else:
print("Sorry,You can't jion us.")
else:
easygui.msgbox("You can't paly the game!")
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/220205/viewspace-2073850/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/220205/viewspace-2073850/
本文通过多个实例介绍如何使用条件判断语句进行编程,包括简单的数值比较、字符大小写判断、商品折扣计算、球队成员资格审查及剩余行驶里程估算等。
872

被折叠的 条评论
为什么被折叠?



