#1.元组元素求和b=(1,2,3,4,5,6,7,8,9)
# b = (1, 2, 3, 4, 5, 6, 7, 8, 9)
# total = 0
# for i in b:
# # print(i)
# total += i
#
# print(total)
2.输出元组内7的倍数及个位为7的数
b = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)
for i in b:
if i % 7 == 0 or i % 10 == 7:
print(i)
3.列表倒数
a=[123,4567,12,3456]
输出 a = [321, 7654, 21, 6543]
第一种方法:
a = [123, 4567, 12, 3456]
for i in a:
temp = 0
while i > 0:
# 第一次 0 +3 == 3 第二次 30+2 = 32 第三次 320+1 =321
temp = temp * 10 + i % 10
i = i // 10 # 12 1 0
print(temp)
# 第二种方式:
a = [123, 4567, 12, 3456]
b = []
for i in a:
i = str(i) # 将int值转换成字符串类型的值
# print(type(i))
# print(i)
i = i[::-1]
print(i)
i = int(i)
print(type(i))
b.append(i)
print