Question

Create a Pascal's Triangle in Python or Atom Javascript the program allows the user to input...

Create a Pascal's Triangle in Python or Atom Javascript

the program allows the user to input any # and creates the triangle from it

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Here I am choosing python3.6 to write code for printing the Pascal triangle for given number of rows as input.

python code (3.6 version):

nrow=int(input("Enter number of rows: ")) #Reading the Number of rows as input
arr=[] #Empty list
for i in range(nrow):
arr.append([])
arr[i].append(1) #Making the list two dimensional
for j in range(1,i):
arr[i].append(arr[i-1][j-1]+arr[i-1][j]) #Adding the values to the list row wise
if(nrow!=0):
arr[i].append(1)
print("Printing the pascal triangle for given input number of rows",nrow)
for i in range(nrow):
print(" "*(nrow-i),end=" ",sep=" ") #printing the spaces in between the numbers
for j in range(0,i+1):
print('{0:6}'.format(arr[i][j]),end=" ",sep=" ") #printing the values on screen
print()

Input and output screenshots:   

input Enter number of rows: 6 Printing the pascal triangle for given input number of rows 6 1 1 2 3 3 1 4 1 10 10 .Program finished with exit code 0 ress ENTER to exit console

please like if you are satisfied with the answer. Thank you

Add a comment
Know the answer?
Add Answer to:
Create a Pascal's Triangle in Python or Atom Javascript the program allows the user to input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT