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
  • JAVASCRIPT: To carry out a program that prints Pascal's triangle, the user must enter the number...

    JAVASCRIPT: To carry out a program that prints Pascal's triangle, the user must enter the number of rows to display.

  • create a python program that requests input from the user for a starting and ending value....

    create a python program that requests input from the user for a starting and ending value. then your program should return all prime numbers between those two values. you will be using input, conditional and control flow statements

  • BANK ATM application program in JAVASCRIPT, that allows the user to manage transaction data. like withdraw,deposit,etc....

    BANK ATM application program in JAVASCRIPT, that allows the user to manage transaction data. like withdraw,deposit,etc. Make sure it produces tabular feedback to the user. (meaning user should be able to enter a quanity let's say $20 withdrawal and balance of $100, so it's balance will be $80..As well to deposit money and add the balance to that deposit. Finally to show (-) signs if balance is overdraw,,,Program reads input from the user though the web page., any help is...

  • Please solve in C++ Pascal's Triangle Videos [edit] write a C++ that asks the user to...

    Please solve in C++ Pascal's Triangle Videos [edit] write a C++ that asks the user to enter the number of rows (N) and then prints the first N rows of Pascal's Triangle, che row per line. Your program should echo print N. Good News [edit] The best way to construct Pascal's Triangle is to use a nested loop with repeated calls to the combination already written for a previous programming assignment, Just #include "myFunctions.h" and use the combination function from...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • in Python: Write a program that allows the user to enter a number between 1-5 and...

    in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...

  • Using Python’s tkinter Graphical User Interface (GUI) module create a Python program to input the number...

    Using Python’s tkinter Graphical User Interface (GUI) module create a Python program to input the number of each type of coin a user has in their possession and then compute and display the total dollar and cents value of these coins. Your solution must accommodate Dollar, Half-Dollar, Quarter, Dime, Nickel, and Penny coins. Your solution must be robust against invalid inputs (i.e., negative value entered into any coin entry widget).

  • USING RAPTOR For the following Programming Challenges, use the modular approach and pseudocode to design a suitable program to solve it. Create a program that allows the user to input a list of first...

    USING RAPTOR For the following Programming Challenges, use the modular approach and pseudocode to design a suitable program to solve it. Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of email addresses where the address is of the following from: first.last@mycollege.edu

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