ITPub博客

首页 > 应用开发 > IT综合 > 与小卡特一起学python 第7章 判断再判断 7-1-2-3-6-7

与小卡特一起学python 第7章 判断再判断 7-1-2-3-6-7

原创 IT综合 作者:yarking207 时间:2016-04-01 17:25:22 0 删除 编辑
#7.1使用比较操作符
num1 = float(input ("Enter the first number:"))
num2 = float(input ("Enter the second number:"))
if num1 < num2:
    print(num1,"is less than",num2)
if num1 > num2:
    print(num1,"is greater than",num2)
if num1 == num2:
    print(num1,"is equal to",num2)
if num1 != num2:
    print(num1,"is not equal to",num2)
#7.2
answer = float(input("Enter a number from 1 to 15"))
if answer >= 10:
    print("You got at least 10!")
elif answer >= 5:
    print("You got at least 5!")
elif answer >=3:
    print("You got at least 3")
else:
    print("You got less than 3.")

#7.6测试多个条件
age = float(input("Enter your age:"))
grade = int(input("Enter your grade:"))
if age > 8:
    if grade >= 3:
        print("You can play this game!")
else:
    print("Sorry.You can't play the game!)
    
#7.7 使用and,or
age = float(input("Enter your age:"))
grade = int(input("Enter your grade:"))
color = input("Enter your favorite color:")
##if age > 8 and grade >=3 and color == "green":
##    print("You can play this game!")
##else:
##    print("Sorry,you can't play the game!")
if color == "red" or color == "bule" or color == "green":
    print("You are allowed to play this game!")
else:
    print("Sorry,you can't play the game")

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/220205/viewspace-2073853/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-08-03

  • 博文量
    65
  • 访问量
    99304