• Python练习_Python初识_day2


     题目

    1.作业

    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、求出下列逻辑语句的值。
    1),8 or 3 and 4 or 2 and 0 or 9 and 7
    2),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、利用if语句写出猜大小的游戏:
    设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。
    
    6、在5题的基础上进行升级:
    给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。
    
    7、使用while循环输出 1 2 3 4 5 6 8 9 10
    
    8、求1-100的所有数的和
    
    9、输出 1-100 内的所有奇数(两种方法)
    
    10、输出 1-100 内的所有偶数(两种方法)
    
    11、求1-2+3-4+5 ... 99的所有数的和
    
    12、⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)
    
    13、简述ASCII、Unicode、utf-8编码关系?
    
    14、简述位和字节的关系?
    
    15、“⽼男孩”使⽤UTF-8编码占⽤⼏个字节?使⽤GBK编码占⼏个字节?

    2.

    2.默写

    1. Bit,Bytes,KB,MB,GB,TB之间的转换关系。
    2. Unicode,utf-8,GBK,每个编码英文,中文,分别用几个字节表示。

    答案

    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

    1)True
    2)False

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

    1),8 or 3 and 4 or 2 and 0 or 9 and 7

    2),0 or 2 and 3 and 4 or 6 and 0 or 3

    1)8
    2)4

    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

    1)6
    2)3
    3)False    # 注意这个
    4)3
    5)True
    6)True
    7)0
    8)3
    9)0
    10)2

    4、while循环语句基本结构?

    while 条件:
        循环体

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

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

    f = 66
    while 1:
        num = int(input('请输入一个数字:'))
        if f == num:
            print('猜测正确')
            break
        elif f > num:
            print('小了')
        else:
            print('大了')

    6、在5题的基础上进行升级:

    给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。

    f = 66
    count = 0
    while 1:
    if count == 3:
    print('太笨了你')
    break
    num = int(input('请输入一个数字:'))
    if f == num:
    print('猜测正确')
    break
    elif f > num:
    print('小了')
    count += 1
    else:
    print('大了')
    count += 1

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

    count = 0
    while count < 10:
        count += 1
        if count == 7:
            continue
        print(count)

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

    while 1:
    sum = 0
    for i in range(101):
    sum += i
    print(sum)
    break

    9、输出 1-100 内的所有奇数(两种方法)

    方法一:
    for i in range(1,101, 2):
        print(i)
    方法二:
    count = 1
    while count < 101:
        if count % 2 == 1:
            print(count)
            count += 2
        else:
            count += 2

    10、输出 1-100 内的所有偶数(两种方法)

    方法一:
    for i in range(2,101, 2):
        print(i)
    方法二:
    count = 2
    while count < 101:
        if count % 2 == 0:
            print(count)
            count += 2
        else:
            count += 2

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

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

    12、⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)

    i = 3
    username = "yangxiaoer"
    password = "123456"
    while i>=0:
        name = input("请输入你的用户名:")
        if name == username:
            passwd = input("请输入你的密码:")
            if passwd == password:
                print("登录成功。请稍后")
                print('''
                username: %s
                password: %s
                '''%(username,password))
                break
            else:
                print("你的密码错误 请重新输入")
                print("你还有%s次机会" % (i-1))
                if i == 0:
                    print('您的机会已经用完,结束本次操作')
                    break
                continue
        else:
            print("你的用户名错误!请重新输入")
            print("你还有%s次机会"%(i-1))
        i -= 1
    
    
    
    username = "yangxiaoer"
    password = "123456"
    i = 3
    while i > 0:
        zh = input("请输入你的账号:")
        i -= 1
        if zh == username:
            mm = input("请输入你的密码:")
            if mm == password:
                print("验证成功.正在登陆......")
                print('''恭喜你登陆成功!
                欢迎用户进入
                用户名 :%s
                密码   :%s
                '''%(zh,mm))
                break
            else:
                if i == 0:
                    print("你的机会已经没了!game over 下次见!")
                    answer = input('再试试?Y or N')
                    if answer == 'Y':
                        i = 3
                print("密码错误,请重新输入")
                print("你还有"+str(i)+"次机会")
        else:
            print("请输入正确的用户名!")
            if i == 0:
                print("你的机会已经没了!")
                answer = input('再试试?Y or N')
                if answer == 'Y':
                    i = 3
            print("你还有" + str(i) + "次机会")
    else:
        print('你TM要不要脸')

    13、简述ASCII、Unicode、utf-8编码关系?

    ASCII码:
        英文:8位
    Unicode:
        英文:32位
        中文:32位
    UTF-8:
        英文:8位
        欧洲文字:16位
        中文:24位

    14、简述位和字节的关系?

    8位 == 1个字节

    15、“⽼男孩”使⽤UTF-8编码占⽤⼏个字节?使⽤GBK编码占⼏个字节?

    UTF-8:9个字节
    GBK:6个字节

    默写

    1.Bit,Bytes,KB,MB,GB,TB之间的转换关系。

    8 bit = 1Bytes
    1024 Bytes = 1KB
    1024 KB = 1MB
    1024 MB = 1GB
    1024 GB = 1TB

    2.Unicode,utf-8,GBK,每个编码英文,中文,分别用几个字节表示。

    Unicode:
        起初:英 16位
                 中16位
        优化:全为32位
            
    utf-8:
        英:8位
        欧:16位
        中:24位
    
    GBK:
        英:8位
        中:16位                

    -

  • 相关阅读:
    Leetcode 12. Integer to Roman
    Leetcode 133. Clone Graph
    Leetcode 199. Binary Tree Right Side View
    Leetcode 200. Number of Islands
    React通过Ajax获取数据
    canvas鼠标点击划线
    制作图片墙
    CSS制作翻牌特效
    输入框制作方法
    初来咋到
  • 原文地址:https://www.cnblogs.com/dongye95/p/10166055.html
Copyright © 2020-2023  润新知