943,947 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 758
  • Python RSS
Nov 3rd, 2009
0

Help with Pascal Triangle Program Please

Expand Post »
I need to write a program that uses the following function

Python Syntax (Toggle Plain Text)
  1. def pascnext( L ):
  2. currentrow = []
  3. if len( L ) == 0:
  4. return [1]
  5. if len( L ) == 1 and L[ 0 ] == 1:
  6. return [ 1, 1 ]
  7. else:
  8. currentrow += [ 1 ]
  9. for i in range( 0, len( L ) - 1 ):
  10. currentrow += [ L[ i ] + L[ i + 1 ] ]
  11. currentrow += [ 1 ]
  12. return currentrow

I need to write another function pascrow(n) where n is a row number in the triangle and returns what that row is in a list. I need pascrow(n) to use the pascnext function though to find it. Any suggestions or help is appreciated!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frank_albers123 is offline Offline
2 posts
since Nov 2009
Nov 4th, 2009
0
Re: Help with Pascal Triangle Program Please
Read the last post of masterofpuppets to your other thread (http://www.daniweb.com/forums/thread235765.html) and you'll nearly have the answer...
Put his code in a function (pascrow), change the for loop condition and the print statement and you've got it
Reputation Points: 64
Solved Threads: 56
Posting Whiz in Training
jice is offline Offline
225 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: I don't know what is causing this error...please help
Next Thread in Python Forum Timeline: Help with string formatting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC