设为首页 加入收藏

TOP

python 2.
2019-03-14 18:08:11 】 浏览:17
Tags:python
1.T or F
1>1 or 3<4 or 4>5 and 2>1 and 9>8 or 7<6
t
not 2>1 and 3<4 or 4>5 and 2>1 and 9>8 or 7<6
f

2.值
8 or 3 and 4 or 2 and 0 or 9 and 7
8
0 or 2 and 3 and 4 or 6 and 0 or 3
4

3.结果
6 or 2>1 #6
3 or 2>1 #3
0 or 5<4 #F
5<4 or 3 #3
2>1 or 6 #T
3 and 2>1 #T
0 and 3>1 #0
2>1 and 3 #3
3>1 and 0 #0
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 or t=2

4.while 循环语句基本结构
while 条件:
循环体(代码块)
else:
条件为假

5.猜大小
while True:
a = int(input("输入数字:"))
if a>66:
print("大")
elif a<66:
print("小")
else:
print("正确")
break

6.3次机会
n = 3
while n>0:
a = int(input("输入数字:"))
if a>66:
print("大")
elif a<66:
print("小")
else:
print("正确")
break
n-=1
print("剩余机会:%d次" % n)
else:
print("太笨了")

7.输出1 2 3 4 5 6 8 9 10
(1)n = 1
while n<11:
if n==7:
n+=1
continue
print(n)
n+=1

(2)n = 1
while n<11:
if n != 7:
print(n)
n+=1

8.1-100和
n = 1
s = 0
while n<=100:
s = s + n
n+=1
print(s)

9.1-100奇数
n = 1
while n<=100:
if n%2 == 0:
n+=1
continue
else:
print(n

)
n+=1

10.1-100偶数
n = 1
while n<=100:
if n%2 == 1:
n+=1
continue
else:
print(n)
n+=1

11.1-2+3-4+5..99的和
(1)n = 1
a = 0
while n <= 99:
a = a + n
n+=2
n = 2
b = 0
while n <= 99:
b = b + n
n += 2
print(a-b)

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

12.3次登录,剩余次数
c = 1
while c <= 3:
name = input("用户名:")
pw = input("密码:")
if name == "zjx" and pw == "123":
print("登录成功!")
break
else:
print("登录失败!")
print("剩余次数:%s" % (3 - c))
c += 1
else:
print("登录错误")

13.过敏词汇
num = input("请输入广告词汇:")
if ("最" or "第一" or "国家" or "稀缺") in num:
print("过敏词汇!")
else:
print("正确!")

编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇python 发送邮件 <QQ+腾讯企业.. 下一篇Python——Pygame实现生命游戏(g..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(217) }