虽然,找规律着实有点投机取巧,哈哈,但确实简单管用。规律:n:输入的行数;(n-2)%4 满足:{1:2,2:3,3:2,0:4}代码如下: while True: try: n = int(input()) dict_map = {1:2,2:3,3:2,0:4} if n <= 2: print(0) else: print(dict_map[(n-2)%4]) except: break