• if判断的流程控制


    if判断的流程控制

    首页

      if语句可以根据用户的输入内容或获取的数据进行条件判断,以响应对应条件的代码块。

      语法:if...else...

      例子:

    username = input("username:")
    password = input("password:")
    if
    username == "george" and password == "georgeNB": print("Welcome My Lord") else: print('Wrong username or password!')

      语法:if...elif...else  用于多条件判断。

      例子一:

    age = 56
    while True:
        user_age = int(input('input your age:'))
        if user_age > age:
            print('try smaller')
        elif user_age < age:
            print('try big')
        else:
            user_age = "exit"
            print('your got it!')
            break

      例子二:

    while True:
        score = int(input("input your score:"))
        if score == 100:
            print("your score 'A++'")
        elif 90 <= score <=95:
            print("your score 'A+' ")
        elif 80 <= score <= 89:
            print("your score 'A'")
        elif 70 <= score <=79:
            print("your score 'B+'")
        elif 60 <= score <=69:
            print("your score 'B'")
        elif score <=59:
            print("your score 'C'")
        else:
            score > 100
            print("Wrong data!")
            break

      # # # 作业 # # #

      # 1、猜年龄,猜三次

    age = 56
    count = 0
    while True:
        user_age = int(input('input your age:'))
        if user_age > age:
            count += 1
            print(count)
            print('try smaller')
            if count >2:
                break
        elif user_age < age:
            count += 1
            print(count)
            print('try big')
            if count >2:
                break
        else:
            user_age = age
            print('your got it!')
            break

      # 2、猜年龄,每隔三次问一次,是否继续(Y/N)

    age = 56
    count = 0
    while True:
        user_age = int(input('input your age:'))
        if user_age > age:
            count += 1
            print(count)
            print('try smaller')
            if count >2:
                print("Do you want to choose to try again(Y/N)")
                choose = input("input your choose:")
                if choose == "Y" or "y":
                    count =0
                else:
                    break
        elif user_age < age:
            count += 1
            print(count)
            print('try big')
            if count >2:
                print("Do you want to choose to try again(Y/N)")
                choose = input("input your choose:")
                if choose == "Y" or "y":
                    count = 0
                else:
                    break
        else:
            user_age = age
            print('your got it!')
            break

      # 3、三次登录(残缺版1.0beta)

    username = "george"
    password = "123"
    count =0
    
    while True:
        input_username = input("input your username:")
        input_password = input("input your password:")
        if username == input_username and password == input_password:
            print("Welconme My Lord!")
            break
        else:
            count +=1
            print("Your username or password is Wrong!")
            if count>2:
                print("Your username or passwrod is Wrong three times, It is lock")
                break

    -------- END --------

  • 相关阅读:
    微信小程序保存图片功能实现
    小程序清除缓存功能如何实现
    小程序自定义函数—数字千位转换
    小程序身份证号检测函数
    小程序 的 textarea 组件 层级问题如何解决
    Markdown 语法背一下咯
    跨域了解一下?
    sort命令的k选项大讨论【转】
    Shell脚本中实现切换用户并执行命令操作【转】
    Ansible Tower系列 四(使用tower执行一个命令)【转】
  • 原文地址:https://www.cnblogs.com/george92/p/12575316.html
Copyright © 2020-2023  润新知