pythonchallenge-10地址 : http://www.pythonchallenge.com/pc/return/bull.html
图片如下:
题目解析:页面显示内容为 len(a[30]) = ?
源代码中有个链接sequence.txt,打开后出现一个未完成的数组 a = [1, 11, 21, 1211, 111221,
题目的意思就是获取这个a[30]的长度。
通过度娘,得出数组的规律是这样的:
a[0]=1,读的就是1个1,于是得a[1] = 11;
a[1]读的为2个1,于是得a[2] = 12;
a[3] = 1211,读为,1个1,1个2,2个1,于是得出a[4] = 11 12 21
解题过程:
num = str(1) times = 30 def readnum(num,times): if times > 0: zz = num[0] j = 0 list = [] for i in str(num): if zz == i: j = j + 1 else: list.append(zz) list.append(str(j)) j = 1 zz = i list.append(zz) list.append(str(j)) num = "".join(list) if times == 1: print(len(num)) times = times - 1 readnum(num,times) else: print("The end")
答案:
5808