标签:python学习 sum pre print else 循环 key python size
1.列表&enumerate
li = ["电脑", "手机", "背包"]
for key, item in enumerate(li,1):
print(key,item)
inp = input("输入商品编号或者商品名:")
inp_num = int(inp)
print(li[inp_num - 1])
2.写个循环
‘‘‘
i = 1
while i < 100:
i += 1
if i % 2 == 1:
print(i)
‘‘‘
j = 1
sum = 0
while j < 101:
j += 1
s = str(j)
temp = j % 2
if temp == 1:
sum = sum + j
s = s + "+" + str(j)
if temp == 0:
sum = sum - j
s = s + "-" + str(j)
# else:
# pass
print(s)
print(sum)
标签:python学习 sum pre print else 循环 key python size
原文地址:http://www.cnblogs.com/Rus7y/p/7363937.html