下面为代码,还有完善的地方:
x = int(input(‘请输一个数:‘)) + 1 a = 0 list1 = [] list2 = [] sum = 0 for n1 in range(x): if n1 % 2 == 0: list1.append(n1) sum = sum - n1 else : list2.append(n1) sum = sum + n1 a = a + n1 print(n1) print(‘偶数为:‘, list1) print(‘奇数为:‘, list2) print(‘1-和为:‘, a) print(‘sum:‘,sum)
时间: 2024-10-13 21:54:54