Created
July 16, 2018 19:27
-
-
Save TomColBee/57cbcb8258ed70e9c54750a8af284711 to your computer and use it in GitHub Desktop.
Coderbyte Python Challenge: PentagonalNumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PentagonalNumber(num) reads num which will be a positive integer and determine how many dots exist in a pentagonal shape | |
# around a center dot on the Nth iteration. | |
# For example, in the image below you can see that on the first iteration there is only a single dot, | |
# on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots. | |
# The formula for this sequence is (5(n-1)^2 + 5(n-1) + 2) / 2 | |
def PentagonalNumber(num): | |
num = num - 1 | |
number = ((5*(num**2)) + (5*num) + 2) / 2 | |
return number | |
# keep this function call here | |
print(PentagonalNumber(input())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment