mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-27 10:22:36 +08:00
Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@ -8,6 +8,7 @@ The square of the sum of the first ten natural numbers is,
|
||||
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
|
||||
Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
suma = 0
|
||||
sumb = 0
|
||||
@ -16,4 +17,4 @@ for i in range(1,n+1):
|
||||
suma += i**2
|
||||
sumb += i
|
||||
sum = sumb**2 - suma
|
||||
print sum
|
||||
print(sum)
|
@ -8,8 +8,9 @@ The square of the sum of the first ten natural numbers is,
|
||||
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
|
||||
Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
|
||||
'''
|
||||
from __future__ import print_function
|
||||
n = int(input())
|
||||
suma = n*(n+1)/2
|
||||
suma **= 2
|
||||
sumb = n*(n+1)*(2*n+1)/6
|
||||
print suma-sumb
|
||||
print(suma-sumb)
|
Reference in New Issue
Block a user