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))
原文地址:https://www.cnblogs.com/zhangdaye/p/9289194.html