Question

Question 1: Pine Tree Write a program that, prints a pine tree consisting of triangles of increasing sizes, filled with a c

Using Python Please

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

'''
Python version : 3.6
Python program to print pine tree of given number of triangles and given symbol
'''

def print_shifted_triangle(n,m,symbol):
   '''
   It prints an n-line triangle , filled with symbol characters,
   shifted m spaces from the left margin
  
   '''
   for i in range(n):
       space = ' '*(m+n-1-i)
       pattern = symbol*(2*i+1)
       print(space+pattern)
      
def print_pine_tree(n, symbol):
   '''
   It prints a sequence of n triangles of increasing sizes
   (the smallest triangle is a 2-line triangle), which forms
   the shape of a pine tree. The triangles are filled with the symbol character.
   '''
   for i in range(n):
       print_shifted_triangle(2+i,n-i-1,symbol)
      
      
def main():
   # input the number of triangles
   n = int(input('Enter the number of triangles : '))
   # input the character to fill the tree with
   symbol = input('Enter the character to fill the tree : ')
   # call the function print_pine_tree to display the pine tree
   print_pine_tree(n,symbol)

# call the main function  
main()  
# end of program      

Code Screenshot:

Python version : 3.6 Python program to print pine tree of given number of triangles and given symbol LIT def print_shifted_tr

Output:

Enter the number of triangles : 4 Enter the character to fill the tree : * 来来来 點點點 點點點點點 點點此 點點點點點 點點點點點點點 點點此 將點點點點 點點點點點點點

Add a comment
Know the answer?
Add Answer to:
Using Python Please Question 1: Pine Tree Write a program that, prints a 'pine tree' consisting...
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
  • Parallelogram Program Write a program that prints the following parallelogram pattern given the the following two...

    Parallelogram Program Write a program that prints the following parallelogram pattern given the the following two inputs. Here are the rules: Your program must work with any length greater than 1. Your program must use the character the user inputs to draw the parallelogram. Your program must not use global variables or global code other than a call to main(). Your program output must match my out exactly. I have provided you with the strings you need for the output...

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle...

    Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle based on the two formal parameters triangle_height giving the triangle height and triangle_char that gives the symbol to be printed. Important notes: This program returns (not prints!) a string. For this function and the other part of this lab you are required to put in a docstring. That will be checked by a TA/grader reading the program. Every one of the occurrences of triangle_char...

  • Using Python Write a program that reads an int N >= 0, then prints out each...

    Using Python Write a program that reads an int N >= 0, then prints out each of the following patterns of *. Here, you may use the * repetition operator, if you wish. Also, each pattern must be output via a single function call to the given named function with single parameter N. Examples for N==4 follow, with explanations of how the displayed diagram reflects this value of N: ) Square with number diagonals, with outer side length of N,...

  • For this lab you will write a small program that prints a few "shapes" using asterisks....

    For this lab you will write a small program that prints a few "shapes" using asterisks. Your program will prompt the user to select a shape by entering a number (square or triangle for B grade, add the zig- zag for the A grade). It will then prompt for the size, and then if a square or triangle is selected it will prompt for "not filled" or "filled", and if azig-zag is selected it will prompt for the number of...

  • plz use python to answer it, thanks in advance 3. Tree and back arcs in a DFS 40 Marks For a given set of digraphs, write a program that performs DFS on each digraph starting at node 0 and prints...

    plz use python to answer it, thanks in advance 3. Tree and back arcs in a DFS 40 Marks For a given set of digraphs, write a program that performs DFS on each digraph starting at node 0 and prints out the total number of tree arcs and back arcs resulting from the traversal. Use our standard convention that when there is a choice of white or grey nodes, the one with the lowest index should be chosen. Input format:...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • c++ program that prints joke and its punchline

    nothing happens when I replace the skeleton code. the program runs but it does not give me the desired results. All the question marks must be removed and filled in with the appropriate code.// Function prototypesvoid displayAllLines(ifstream &infile);void displayLastLine(ifstream &infile);int main(){// Arrays for file nameschar fileName1[SIZE];char fileName2[SIZE];// File stream objectsifstream jokeFile;ifstream punchlineFile;// Explain the program to the user.cout << "This program will print a joke "<< "and its punch line.\n\n";// Get the joke file name.cout << "Enter the name of...

  • Write a C program to do the following: 1. Write a C function named find that...

    Write a C program to do the following: 1. Write a C function named find that receives a one-dimensional array of type character named arr and its size of type integer. After that, the function must select a random index from the array. The function must find if the character stored in the randomly selected index comes before all the characters to its left alphabetically. Finally, the function prints to the screen the element if the element meets the condition...

  • This program should be run on Visual Studio. Please use printf and scanf as input and...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.11 Lab Exercise Ch.6a: Functions: String analyzer Create and debug this program in Visual Studio. Upload your Source.cpp file for testing (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: ics Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have...

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