SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 5 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 11 Oct 2017 My Price 10.00

For Intro to Python Class (Currently learning about functions)

For Intro to Python Class (Currently learning about functions)

 

 

Pascal's triangle is a geometric arrangement of sums that have interesting mathematical properties -- most famously, the binomial coefficients. 

The rows of Pascal's triangle are conventionally enumerated starting with row 0, and the numbers in each row are usually staggered relative to the numbers in the adjacent rows.

A simple construction of the triangle proceeds in the following manner.

  • On row 0, write only the number 1.
  • Then, to construct the elements of following rows, add the number directly above and to the left with the number directly above and to the right to find the new value.
  • If either the number to the right or left is not present, substitute a 0 in its place.

For example, the first number in row 1 is 0 + 1 = 1, whereas the numbers 1 and 3 in row 3 are added to produce the number 4 in row 4. Here are the first six rows of Pascal's triangle. 

           
                       1
                     1   1
                   1   2   1 
                 1   3   3   1
               1   4   6   4   1
             1   5  10  10   5   1

In the file problem3.py, write a program that prompts the user for the height of Pascal's triangle and then prints out the triangle in the same style as in the previous example. Height 1 would print a triangle containing a single row. 

Hint: Use a list for each row, and use a list of lists to hold the whole triangle. Think about how the position of each number in the triangle can be translated to indices in the lists. There are many ways to solve this problem, but one is to keep placeholders in the list to represent "empty" cells in each row. Only every second entry would actually contain a number. This makes it easy to find the left and right parent of each cell. 

Once the triangle includes three-digit numbers or longer, the alignment will become broken. This is okay, as long as the output of each line is centered.

Answers

(5)
Status NEW Posted 11 Oct 2017 06:10 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)