码迷,mamicode.com
首页 > 其他好文 > 详细

20181018练习

时间:2018-10-18 22:00:11      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:没有   退出   等于   inpu   后退   password   就是   内容   理想   

#  1、判断下列逻辑语句的True,False.
# # 运算的优先级
# () -> not -> and -> or
# 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
# False True False True True False =True
# 2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
# True True F False True F True False = F
# 2、求出下列逻辑语句的值。优先 -> not -> and -> or
# 1),8 or 3 and 4 or 2 and 0 or 9 and 7
# 8 or 4 or 0 or 7 =8
# 2),0 or 2 and 3 and 4 or 6 and 0 or 3
# 0 or 4 or 0 =4
# 3、下列结果是什么?优先 -> not -> and -> or
# 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
# T and 2 or T and 3 and 4 or T
# 2 or 4 or T = 2
# 4、while循环语句基本结构?
‘‘‘
while 条件:
while语句块(循环体)
运行: 判断你给的条件是否为真,如果真则执行循环体。
否则跳出循环。执行完循环体之后再次判断条件是否为真
‘‘‘
# 5、利?while语句写出猜??的游戏:
# 设定?个理想数字?如:66,让?户输?数字,如果?66?,则显示猜测
# 的结果?了;如果?66?,则显示猜测的结果?了;只有等于66,显示猜测结果
# 正确,然后退出循环。
# num = 66
# while True:
# content = int(input("请输入数字: "))
# if content == num :
# print("对了")
# break
# else:
# print("再试试")
# 6、在5题的基础上进?升级:
# 给?户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循
# 环,如果三次之内没有猜测正确,则?动退出循环,并显示‘太笨了你....’。
# num = 66
# count = 1
# while count <= 3:
# guess = int(input("请输入你猜的数字:"))
# if guess == num:
# print("恭喜你,猜对了!!!")
# break
# else:
# if count == 3:
# print("你都猜3次还没猜中.....太笨了你..........")
# break
# print("你猜的数字不对,请重新再猜..........")
# count += 1
# 7.使?while循环输? 1 2 3 4 5 6 8 9 10
# count = 0
# while count <=10:
# print(count)
# count +=1
# 8.求1-100的所有数的和
# num = 1
# sum = 0
# while num <= 100:
# sum = sum + num
# num = num + 1
# print(sum)
# 9.输出 1-100 内的所有奇数
# count = 0
# while count <= 100 :
# if count %2==1:
# print(count)
# count +=1
# 10.输出 1-100 内的所有偶数
# count = 0
# while count <= 100 :
# if count %2==0:
# print(count)
# count +=1
# 11.求1-2+3-4+5 ... 99的所有数的和.
‘‘‘给num 赋值为1,sum赋值为0,当num 的赋值小于100的时候while循环,
temp的赋值等于num 和2的余数,如果temp的赋值等于1,sum的赋值就等于
sum加num 的赋值(余数为1,num 就是奇数),否则sum的赋值就等于sum减num 的
赋值(余数不为1就为0,num 就是偶数),num 重新赋值
等于num 加1,一直加到num 的赋值等于99,while循环为假!打印sum‘‘‘
# num = 1
# sum = 0
# while num < 100:
# temp = num % 2
# if temp == 1:
# sum = sum + num
# else:
# sum = sum - num
# num = num + 1
# print(sum)
# 12.?户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使?字符串格式化)
# name = "张三李四"
# password = "123"
# i = 2
# while i >= 0 :
# username = input("请输入用户名:")
# password1 = input("请输入密码:")
# if username == name and password1 == password :
# msg = ‘‘‘欢迎%s登陆‘‘‘%(username)
# print(msg)
# break
# else:
# print("账号或密码错误,请重新输入!")
# print("还有" + str(i) + "次机会!")
# i -= 1
# 13. ?户输??个数. 判断这个数是否是?个质数(升级题).
# num = int(input(‘请输入数字:‘))
# for i in range(2,num):
# # print(i)
# if num % i == 0:
# print(‘这不是一个质数啊‘)
# break
# else:
# print(‘good‘)
‘‘‘14. 输??个?告标语. 判断这个?告是否合法. 根据最新的?告法来判断. ?
告法内容过多. 我们就判断是否包含‘最‘, ‘第?‘, ‘稀缺‘, ‘国家级‘等字样. 如果包
含. 提示, ?告不合法‘‘‘
# ①
‘‘‘content = input(‘输入:‘)
if ‘最‘ in content or ‘第一‘ in content or ‘稀缺‘ in content or ‘国家级‘ in content:
print(‘不合法‘)
else:
print(‘合法‘)‘‘‘
#②
‘‘‘content = input (‘输入标语:‘)
list = [‘最‘,‘第一‘,‘稀缺‘,‘国家级‘]
for i in list:
if i in content:
print(‘不合法‘)
break
else:
print(‘合法‘)‘‘‘
# 15输??个数. 判断这个数是?位数(?算法实现)(升级题)
# num = input(‘>>>‘)
# count = 0
# while count < len(num):
# count += 1
# print(‘这是一个%s位数‘% count)

20181018练习

标签:没有   退出   等于   inpu   后退   password   就是   内容   理想   

原文地址:https://www.cnblogs.com/chenshanqin/p/9812995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!