Skip to content

Instantly share code, notes, and snippets.

@kaiquewdev
Created October 28, 2011 01:31
Show Gist options
  • Save kaiquewdev/1321411 to your computer and use it in GitHub Desktop.
Save kaiquewdev/1321411 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# -*- coding: utf8 -*-
class Naturals(object):
def __init__(self, n):
self.n = n
def sum_square(self):
for i in range(self.n):
i = i**2
return i
def square_sum(self):
for i in range(self.n):
i += i
return i**2
def between_sum(self):
if self.sum_square > self.square_sum:
return self.sum_square() - self.square_sum()
else:
return self.square_sum() - self.sum_square()
#Init method
natural = Naturals(100)
#Sum Saquare
print 'Soma dos Quadrados: {0}'.format(natural.sum_square())
#Square Sum
print 'Quadrados das somas: {0}'.format(natural.square_sum())
#Diference
print 'Diferença da soma dos quadrados: {0}'.format(natural.between_sum())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment