1.判断下列逻辑语句的结果,一定要自己先分析

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

Ture

print(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

False

print(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

​ 8

print(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

4

print(0 or 2 and 3 and 4 or 6 and 0 or 3)

3)1 and 0 or 8 and 9 and 5 or 2

5

print(1 and 0 or 8 and 9 and 5 or 2)

4)4 or 8 and not False and 8 or 9

4

print(4 or 8 and not False and 8 or 9)

3.下列结果是什么? (2>1这种是一体)

  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

    True

  6. 3 and 2 > 1

    True

  7. 0 and 3 > 1

    0

  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.简述ASCII、Unicode、utf-8编码

ASCII : (老美)不支持中文

Unicode: ( 万国码)英文16 位 中文 32位

utf-8 : (可变长的编码) 英文8位 欧洲文 16位 亚洲24位

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

1字节 = 8位

1Bytes = 8bit

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

While 空格 条件 冒号

缩进 循环体

while 空格 条件 冒号

缩进 循环体

else 冒号

缩进 结果

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

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

num = 66
count = 0
while count < 3:
name = int(input("请输入数字:"))
if name > num:
print("大了")
elif name < num:
print("小了")
else:
print("正确")
break
count = count + 1
else:
print("你太笨了") 这是第八题的答案
第七题答案如下 num = 66
while True:
name = int(input("请输入数字:"))
if num > name:
print("小了")
elif num < name:
print("大了")
else:
print("正确")
break

8.在7题的基础上进行升级:

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

num=66
n=3
while n:
num1=int(input("请输入猜测数字"))
n-=1
if num1==num:
print("猜测正确!")
break
elif num1>num:
print("猜大了")
else:
print("猜小了")
else:
print("你太笨了",end="")

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

num = 1
while num <= 10:
print(num)
num = num + 1 ❌ num = 1
while 1 <= num <= 6:
print(num)
num = num + 1
continue
num = 8
while 8 <= num <= 10:
print(num)
num = num + 1

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

i = 0
num = 0
while i <= 99:
i = i + 1
num = num + i
print(num)
#5050

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

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

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

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

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

num = 0
n = 1
while n < 100:
if n % 2 == 0:
num = num - n
else:
num = num + n
n = n + 1
print(num) #50 num = 1
j_sum = 0
o_sum = 0
while num < 100:
if num % 2 == 1:
j_sum = j_sum + num
elif num % 2 == 0:
o_sum += num
num = num + 1
print(j_sum - o_sum) num = 1
num_sum = 0
while num < 100:
if num % 2 == 1:
num_sum += num
elif num % 2 == 0:
num_sum -= num
num = num + 1
print(num_sum)

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

  1. name="alex"
    psd="admin123" n=3
    while n:
    n=n-1
    num1=input("请输入账号:")
    psd1=input("请输入密码:")
    if num1==name and psd==psd1:
    print("成功登陆!")
    break
    else:
    print("账号或密码错误,你还剩下%d次机会"%(n)) 自己使用的方法:
    n = 3
    while n:
    name = input("请输入账户")
    n -= 1
    if name == "alex":
    print("输入正确")
    break
    else:
    name1 = "你还有%d次机会"
    print(name1%(n))

while 循环,运算符,字符串的格式化练习的更多相关文章

  1. while 循环,运算符,字符串的格式化

    1.while 关键字 (死循环) while 条件: 循环体 条件:只要条件是 Ture就可以循环. while 空格 条件 冒号 缩进 循环体 while else while 空格 条件 冒号 ...

  2. 总结day2 ---- while循环的简单使用, 格式化输出.运算符.以及编码的应用

    内容提要 一 : while 循环 while 的基本语句操作 如何终止循环 二 :格式化输出 三 :运算符号 四 :编码初识别 一 : while 循环 1  >>>>whi ...

  3. 字符串的格式化、运算符和math函数(python中)

    一.字符串的格式化 1.字符串格式化输出 print('%s的年龄是%d' % ('小哥哥',20)) # 将每个值放在⼀个圆括号内,逗号隔开 '{0}的年龄是{1}'.format('⼩小哥哥',2 ...

  4. yield生成器及字符串的格式化

    一.生成器 def ran(): print('Hello world') yield 'F1' print('Hey there!') yield 'F2' print('goodbye') yie ...

  5. Python基础->for循环、字符串以及元组

    python流程控制>for循环.字符串以及元组 学习有关序列的思想.序列:一组有顺序的东西.所有的序列都是由元素组成的,序列中的元素位置是从0开始编号的,最后一个元素的位置是它长度减一. fo ...

  6. 010.Python字符串的格式化

    字符串的格式化 顺序传参 索引传参 关键字传参 容器类型传参(列表和元组) {}相当于占位符 1 顺序传参 strvar = "他{}牺牲自己,{}出卖组织" res = strv ...

  7. PHP json字符串,格式化缩进显示

    PHP json字符串,格式化显示 /** * 格式化 */ class JsonFormatHelper { /** * json字符串缩进显示 * @param unknown $json * @ ...

  8. C Primer Plus_第四章_字符串和格式化输入输出_编程练习

    Practice 1.输入名字和姓氏,以"名字,姓氏"的格式输出打印. #include int main(void) { char name[20]; char family[2 ...

  9. 使用指定格式的字符串变量格式化日期字符串,DateAndTime取时间间隔

    private void btn_GetTime_Click(object sender, EventArgs e) { lab_time.Text = DateTime.Now.ToString(& ...

随机推荐

  1. 二叉树基本操作C代码

    #include<stdio.h> #include<malloc.h> #define LEN sizeof(struct ChainTree) struct ChainTr ...

  2. 类选择器和所作用的标签一起写为什么不起作用? - CSDN博客

    原文:类选择器和所作用的标签一起写为什么不起作用? - CSDN博客 HTML代码: css样式: 这不是将样式作用于circle类下的有current类的li标签吗?为什么不起作用? 原因: 选择器 ...

  3. 【Python】:拓展Queue实现有序不重复队列

    最近手头有个需求是这样的,定期检查数据库获取失败任务并且进行重启.最早想到的是添加一个生产者&&消费者队列,但是发现很多棘手的问题. 1.重启任务是调用的一个shell脚本然后在脚本中 ...

  4. UWP 双向绑定,在ListView中有个TextBox,怎么获取Text的值

    要求:评论宝贝的时候一个订单里面包含多个产品,获取对产品的评论内容哦 1. xaml界面 <ListView x:Name="lvDetail"> <ListVi ...

  5. Unity开发概览(HoloLens开发系列)

    本文翻译自:Unity development overview 要开始使用Unity创建全息应用,点此安装包含Unity HoloLens技术预览的开发工具.Unity HoloLens技术预览基于 ...

  6. Linux iostat

    转自 http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858810.html Linux IO实时监控iostat命令详解 简介 iostat ...

  7. Uncaught (in promise)

    Uncaught (in promise) 使用es6的promise时候,有时候会出现如下错误: 这是因为,使用定义promise方法的时候,reject了,但是,在使用的地方没有用catch进行接 ...

  8. WebBrowser执行脚本和调用外部方法

    控制WebBrowser实际上就是控制IE,最简单的方法就是执行javascript或vbscript,省去了接口的转换.如何执行脚本?以前我一直用mshtml中IHTMLWindow2接口的exec ...

  9. Controls 属性与继承 TShape 类的小练习(使用TShape可以解决很多图形问题)

    本例效果图: 代码文件: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, ...

  10. 工作中vue项目前后端分离,调用后端本地接口出现跨域问题的完美解决

    在我们实际开发中,选择不错的前端框架可以为我们省掉很多时间,当然,有时我们也会遇到很多坑. 最近在做vue项目时就遇到了跨域问题,一般来说,出现跨域我们第一反应使用jsonp,但是这个只支持get请求 ...