zoukankan      html  css  js  c++  java
  • day 2 作业

     1、判断下列逻辑语句的True,False.

    1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
    2) not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6


    2、求出下列逻辑语句的值。

    print(8 or 3 and 4 or 2 and 0 or 9 and 7)
    print(0 or 2 and 3 and 4 or 6 and 0 or 3)


    3、下列结果是什么?
    1)、6 or 2 > 1
    2)、3 or 2 > 1
    3)、0 or 5 < 4
    4)、5 < 4 or 3
    5)、2 > 1 or 6
    6)、3 and 2 > 1
    7)、0 and 3 > 1
    8)、2 > 1 and 3
    9)、3 > 1 and 0
    10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2



    4,while 循环语句的基本结构


    5、利while语句写出猜大小的游戏:

          设定个理想数字如:66,让户输数字,如果比66大,则显示猜测的结果大了;如果66,则显示猜测的结果了;只有等于66,显示猜测结果 正确,然后退出循环。

           

    count = int(input("请输入一个数字:"))
    while True:
       if count > 66:
           print("大了")
       elif count < 66:
            print("小了")
       else:
            print("恭喜你")
            break




    6,在5题的基础上进行升级: 给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。
    from random import  randint
    
    count = 1
    n = randint(1, 100)
    
    while count <= 3:
        num = int(input("请猜:"))
        if num > n:
            print("猜大了")
        elif num < n:
            print("猜小了")
        else:
            print("猜对了")
            break
        count = count + 1
    else:
        print("太笨了")



    7,使用while循环输出 1 2 3 4 5 6 8 9 10

    count = 1
    while count <= 10:
        if count != 7:
            print(count)
        count += 1
    
    
    
    count = 1
    while count <= 10:
        if count == 7:
            count += 1
            continue # 停止当前本次循环. 继续执行下一次循环
        print(count)
        count += 1

    8.求1-100的所有数的和

    count = 1
    sum = 0
    while count <= 100:
        sum += count
        count += 1
    print(sum)

    9.输出 1-100 内的所有奇数

    count = 1
    while count <= 100:
        if count % 2 == 1:
            print(count)
        count += 1

    10.输出 1-100 内的所有偶数

    count = 1
    while count <= 100:
        if count % 2 == 0:
            print(count)
        count += 1




    count = 2
    while count <= 100:
    print(count)
    count += 2


    11.求1-2+3-4+5 ... 99的所有数的和.

    1+3+5+7+9....+99 - 2-4-6-8-10
    
    sum = 0
    count = 1
    while count <= 100:
        if count % 2 == 1: # 奇数
            sum += count
        else: # 偶数
            sum -= count
        count += 1
    print(sum)
    12.用户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使用字符串格式化)

    count = 1
    while count <= 3:
        # 让用户输入用户名和密码
        username = input("请输入用户名:")
        password = input("请输入密码:")
        if username == 'alex' and password == '123':
            print("恭喜你, 登录成功!")
            break
        else:
            print("用户名或密码错误!")
        print("当前登录了%s次, 剩余%s次" % (count, 3-count))
        count = count + 1



    14. 输入一个广告标语. 判断这个广告是否合法. 根据最新的广告法来判断. 广告法内容过多. 我们就判断是否包含'最', '第一', '稀缺', '国家级'等字样. 如果包 含. 提示, 广告不合法

    ads = input("请输入你的广告标语:")
    if "" in ads or "第一" in ads or "稀缺" in ads or "国家级" in ads:
        print("不合法的广告")
    else:
        print("合法的广告")


















         

  • 相关阅读:
    图片在网页中不能显示
    利用QQWry.dat显示客户IP所在地 [转贴]
    asp.net时间戳与系统时间互转 mssql
    酷友网 http://www.kuiu.cn/ 再次上线了!!!
    string.Format .net string 补空
    ASP.net中md5加密码的方法[转]
    C#中|(位或)和||(逻辑或)有什么区别?
    .net身份证号码验证
    实用jquery代码片段集合
    ERROR: “System.Web.Mvc.Controller.File(string, string, string)”是一个“方法”
  • 原文地址:https://www.cnblogs.com/xiaomai-rhce/p/10174480.html
Copyright © 2011-2022 走看看