提交时间:2025-05-17 10:23:50

运行 ID: 322644

n = int(input("请输入n的值(1 <= n <= 100):")) if n < 1 or n > 100: print("输入的n不在有效范围内!") else: total = 0 current_term = 1 # 初始为1,第一次循环会乘以2 for _ in range(n): current_term *= 2 total += current_term print(f"2 + 2*2 + 2*2*2 + ... + 2^{n} 的和是:{total}")