and与or的用法
#1.判断下列语句的True和False
# 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 结果为True
# print(1>1or 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
# 2),0 or 2 and 3 and 4 or 6 and 0 or 3 值为4
#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 结果为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、while循环语句句基本结构?
# while 条件:
# 代码块1(循环体)
# else:
# 代码块2
# 判断条件是否为真,若条件为真,则执行代码块1.
# 再次判断条件是否为真,直到条件为假时,执行else代码块2跳出循环体.
# 5、利用while语句写出猜大小的游戏:
# 设定一个理想数字比如:66,让用户输入数字,如果比66大,
# 则显示猜测 的结果大了;如果比66小,则显示猜测的结果小了;
# 只有等于66,显示猜测结果 正确,然后退出循环。
# while True:
# num=int(input("请输入一个数字"))
# if num==66:
# # print("猜测正确")
# # break
# # if num>66:
# # print("结果大了")
# # continue
# # if num<66:
# # print("结果小了")
# continue
# 6、在5题的基础上进行升级: 给用户三次猜测机会,
# 如果三次之内猜测对了,则显示猜测正确,退出循 环,如果
# 三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。
# count=1
# # while count<=3:
# # num = int(input("请输入数字:"))
# # if num==66:
# # print("猜测正确")
# # break
# # if num>66 and count<3:
# # print("结果大了")
# # if num<66 and count<3:
# # print("结果小了")
# # count=count+1
# # else:
# # print("太笨了你....")
#7.使用while循环输入 1 2 3 4 5 6 8 9 10
# count=0
# while count<10:
# count=count+1
# if count==7:
# continue
# print(count)
#8.求1-100数的总和
# count=1
# sum=0
# while count<=100:
# sum=sum+count
# count=count+1
# print(sum)
#9.输出1-100数的奇数
# count=1
# while count<=100:
# if count%2 !=0:
# count=count+1
# print(count)
#10.输出1-100数的偶数
# count=1
# while count<=100:
# if count%2 ==0:
# count=count+1
# print(count)
#11.
# count=1
# sum=0
# while count<=99:
# if count%2==1:
# sum=sum+count
# if count%2==0:
# sum=sum-count
# count=count+1
# print(sum)
#12.用户只有三次输入机会,判断其过程?
# count=1
# while count<=3:
# username = input("请输入用户名:")
# password = input("请输入密码:")
# if username!="ZMC" or password!="1996":#用户名为ZMC,密码为1996
# print("还有%d次机会输入" % (3-count))
# else:
# print("用户名密码输入正确!")
# break
# count=count+1
#13. 用户输入一个数. 判断这个数是否是一个质数(升级题).
#hile True:
# s = int(input('请输入一个数字:'))
# if s <= 1:
# print('不是质数' )
# elif s == 2 :
# print('是质数')
# else :
# i = 2
# while s > i :
# if s % i == 0 :
# print('%s不是质数' % s)
# break
# i += 1
# else :
# print('%s是质数'% s)
# 14.在输入的广告标语中,判断其是否出现了不合法的词汇?
# while True:
# adv=input("请输入广告标语:")
# if ("第一" or "最" or "国家级") in adv:
# print("不合法")
# else:
# print("合法") #15.输入一个数字,判断其是几位数?
# a=0
# b=int(input("输入的数字"))
# while b!=0:
# b=b//10
# a=a+1
# print("数字是%s" % (a))
and与or的用法的更多相关文章
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
- 【JavaScript】innerHTML、innerText和outerHTML的用法区别
用法: <div id="test"> <span style="color:red">test1</span> tes ...
- chattr用法
[root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...
- 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)
vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...
- [转]thinkphp 模板显示display和assign的用法
thinkphp 模板显示display和assign的用法 $this->assign('name',$value); //在 Action 类里面使用 assign 方法对模板变量赋值,无论 ...
随机推荐
- ES6之箭头表达式
ES2015新增的特性箭头表达式,省去了关键词function,文中``双撇号和${}是Typescript的语法.以下是一些学习笔记: 1.单行箭头表达式: var foo = (arg1,arg2 ...
- sql 查询重复数据,删除重复数据,过滤重复数据
select * from (SELECT titleid,count(titleid) c FROM [DragonGuoShi].[dbo].[ArticleInfo] group by titl ...
- Oracle查询表占用空间的大小
select * from (select OWNER, segment_name, segment_type, sum(bytes) mmm from dba_segments where /*ta ...
- 关于toolchain(工具链)的一点知识
之前一直觉得toolchain是个高大上的东西,现摘录 uClibc中的FAQ以助理解. A toolchain consists of GNU binutils, the gcc compiler, ...
- [4]传奇3服务器源码分析一 SelGate
1. 2 留存 服务端下载地址: 点击这里
- [转]js刷新父窗体
浮层内嵌iframe及frame集合窗口,刷新父页面的多种方法 <script language=JavaScript> parent.location.reload(); ...
- 20155228 获取技能的成功经验和关于C语言学习的调查
内容提要 你有什么技能比大多人(超过90%以上)更好?针对这个技能的获取你有什么成功的经验?与老师博客中的学习经验有什么共通之处? 有关C语言学习的调查 你是怎么学习C语言的?(作业,实验,教材,其他 ...
- 20165305 苏振龙《Java程序设计》第八周课上测试补做
1. 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入world.sql,提交导入成功截图 2. ...
- Vue:将px转化为rem,适配移动端vant-UI等框架(px2rem-loader)
转载:https://www.cnblogs.com/WQLong/p/7798822.html 1.下载lib-flexible 使用的是vue-cli+webpack,通过npm来安装的 npm ...
- tomcat2章1
package ex02.pyrmont; import java.io.File; public class Constants { public static final String WEB_R ...