if语句简单练习

  1. input练习
# -*-coding:utf-8 -*-
# import getpass     隐藏只能在cmd中使用
user=input("请输入账号:")

password=input("请输入密码:")
print(user)
print(password)

2.if elif 语句

# -*-coding:utf-8 -*-
age=int(input("请输入年龄:"))
if age>=18:
    print("你可以去网吧了")
elif age>=15:
    print("你可以谈恋爱了")
elif age>=12:
    print("你可以去上学了")
  1. if else 语句
# -*-coding:utf-8 -*-
age=int(input("请输入年龄:"))
if age>=18:
    print("你可以去网吧了")
else:
    print("你不能去网吧")
  1. if elif else 语句
# -*-coding:utf-8 -*-
age=int(input("请输入年龄:"))
if age>=18:
    print("你可以去网吧了")
elif 12<age<18:
    print("你可以上初中了")
else:
    print("你可以上小学了")
  1. if 嵌套语句
# -*-coding:utf-8 -*-
age=int(input("请输入年龄:"))
if age>=18:
    print("你可以去网吧了")
    if age>22:
        print("你可以结婚了")
    else:
        print("你可以谈恋爱了")
else:
    print("你还未成年")
原文地址:https://www.cnblogs.com/lav3nder/p/11121774.html