#-*-coding:utf-8-*- ‘‘‘ 计算 1-2+3-4+5...+99 ‘‘‘ sum = 0 for i in range(1,100): if i%2 ==0: sum = sum - i else: sum +=i print(sum)
#-*-coding:utf-8-*- ‘‘‘ 计算 1-2+3-4+5...+99 ‘‘‘ i = 1 sum = 0 while i<100: if i%2 ==0: sum = sum - i else: sum +=i i= i+1 print(sum)
原文地址:https://www.cnblogs.com/sunnybowen/p/10230956.html
时间: 2024-11-05 23:36:31