首页 > 其他 > 详细

练习题

时间:2018-03-29 18:03:48      阅读:183      评论:0      收藏:0      [点我收藏+]
team1 = [‘a‘,‘b‘,‘c‘]
team2 = [‘x‘,‘y‘,‘z‘] #a 不和x对战,b 不和y,z 对战
# for i in team1: #法一
# for j in team2:
# if i == ‘a‘ and j == ‘x‘:
# continue
# elif i == ‘c‘ and (j == ‘y‘ or j ==‘z‘):
# continue
# else:
# print(‘%s VS %s‘%(i,j))

for t1 in team1: #法二
if t1 == ‘a‘:
tmp = team2[team2.index(‘x‘)+1:] #返回x 的索引
elif t1 == ‘b‘:
tmp = team2[:team2.index(‘y‘)] #返回 y 的索引
else:
tmp = team2
for t2 in tmp:
print(‘%s VS %s‘%(t1,t2))
def func(x):
if x > 0 :
func(x-1)
print(x)
func(5)
输出结果: 1 2 3 4 5 (递归)
循环删list元素

li = [1,1,2,3,4,5,6,7,8,9]
for i in li:
if i%2!=0:
li.remove(i)
print(li)
输出结果: [1, 2, 4, 6, 8]
 

练习题

原文:https://www.cnblogs.com/chendai21/p/8310560.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!