zoukankan      html  css  js  c++  java
  • Day1_Python基础_13.表达式if ... else

    场景一、用户登陆验证

    # Author: George.Wang
    import getpass
    _Username="George"
    _Password="abc123"

    Username=input("Please input your name:")
    #Password=input("PLsease input your password:")
    Password=getpass.getpass("Please input your password:") #pycharm中会有问题,python console可用

    if Username==_Username and Password==_Password:
    print("Hi,{name} Welcome to login this system!".format(name=Username))
    else:
    print("Warning!Our system have an attack!")
    print("新的程序段,必须顶着开始,不得有空格或非法缩进,此例为错误")
     

    场景二、猜年龄游戏

    在程序里设定好你的年龄,然后启动程序让用户猜测,用户输入后,根据他的输入提示用户输入的是否正确,如果错误,提示是猜大了还是小了

    my_age = 32
    guess_my_age = int(input("You can guess my age:"))
    if guess_my_age < my_age :
    print("I'm sorry, your answer is smaller than that...let's try again.")
    elif guess_my_age == my_age:
    print("Congratulations! you have got the right age.")
    else:
    print("I'm sorry, your answer is bigger than that...let's try again.")
    外层变量,可以被内层代码使用
    内层变量,不应被外层代码使用
     
  • 相关阅读:
    About cookie
    关于在Servlet中的Fileter
    看完这篇正则表达式,50岁的马化腾眼睛湿润了
    Tutorial中的hello2代码
    Development descriptor
    What is the Annotation?
    剖析容器的注入技术
    LDAP & Implentation
    RESTful levels、HATEOAS
    Mysql8.0导入数据时出错
  • 原文地址:https://www.cnblogs.com/wangcx/p/6701016.html
Copyright © 2011-2022 走看看