[Tutor] Quick Programming Question
Alan Gauld
alan.gauld at btinternet.com
Sat Oct 3 01:42:51 CEST 2015
On 02/10/15 17:41, Jared Johnson via Tutor wrote:
> "A pentagonal number is defined as
> n(3n - 1)/2 for n = 1,2 etc.
> Write a function with the following header that returns a pentagonal number:
> def getPentagonalNumber(n):
It's asking you to write a function that returns the
result of the equation.
Here is a simpler example
Write a function with the following header that
returns a squared number:
def getSquare(n):
And the solution looks like:
def getSquare(n):
return n*n
You need something similar for your pentagonal numbers.
> Write a test program that uses this function to display the
> first 100 pentagonal numbers with 10 numbers on each line."
I assume you know how to use for loops?
This is just a nested for loop. The outer for the 10 lines
and the inner for the 10 values per line
If you need more help then reply explaining which bits
you are confused about and we can break it down further.
Note: as policy we do not provide solutions to homeworks
but we will give suggestions/hints etc.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list