Help with Pascal Triangle Program Please

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2009
Posts: 2
Reputation: frank_albers123 is an unknown quantity at this point 
Solved Threads: 0
frank_albers123 frank_albers123 is offline Offline
Newbie Poster

Help with Pascal Triangle Program Please

 
0
  #1
31 Days Ago
I need to write a program that uses the following function

  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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 149
Reputation: jice is on a distinguished road 
Solved Threads: 38
jice jice is offline Offline
Junior Poster
 
0
  #2
30 Days Ago
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
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC