第二天 python 作业

以下的内容必须自己先进行推导

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

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

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

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

3.下列结果是什么?

1)、6 or 2 > 1       6
2)、3 or 2 > 1       3
3)、0 or 5 < 4       False
4)、5 < 4 or 3       3
5)、2 > 1 or 6       False
6)、3 and 2 > 1      True
7)、0 and 3 > 1      False
8)、2 > 1 and 3      3
9)、3 > 1 and 0      0
10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2   2

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

while 条件:
    循环体

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

设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。
num = 66
while True:
    guess = int(input("请输入数字"))
    if guess > num:
        print("猜大了")
    elif guess < num:
        print("你猜小了")
    else:
        print("你猜对了")
        break

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

给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。
num = 66
count = 0
while count <3:
    guess = int(input("请输入数字"))
    if guess > num:
        print("猜大了")
    elif guess < num:
        print("你猜小了")
    else:
        print("你猜对了")
        break
    count += 1
else:
    print("你太笨了")

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

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

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

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

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

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

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

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

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

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

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

num = 3
while num > 0:
    name = input("请输入登录名")
    password  = input("请输入密码")
    if name == "yuan" and password == "123"
        print("登录成功")
        break
    else:
        num -= 1
        print("名字或密码错误剩余%s次数" % num)
    

13.简述ASCII、Unicode、utf-8编码

ASCII : 英文一个字节,不支持中文
Unicode(万国码):英文四个字节,中文四个字节。
UTF-8:英文一个字节,亚洲两个字节,欧洲三个字节

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

1字节==8位(1Byte==8bit)

转载于:https://www.cnblogs.com/yuancw/p/11448041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值