Hello. I'm using functions in my python code. I'm not sure how to get the output.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello. I'm using functions in my python code.

I'm not sure how to get the output.

### Program Instructions

- The program should have a `main` function that reads three inputs: a symbol and two integer values. It will then draw figures similar to the sample run.
  - The `main` function should call the `drawRectangle` and `drawTriangle` functions.
- `drawBar(symbol, length)` function:
  - Uses a loop to draw a horizontal bar of specified length with the given symbol.
- `drawRectangle(symbol, width, height)` function:
  - Takes three arguments and calls the `drawBar` function.
- `drawTriangle(symbol, height)` function:
  - Takes two arguments and calls the `drawBar` function.
- Your output should match the given sample run.

### Sample Run 1

```
Enter the symbol to draw the shapes: X
Enter the width of the shape: 7
Enter the height of the shape: 5
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX

X
XX
XXX
XXXX
XXXXX
XXXX
XXX
XX
X
```

This sample demonstrates the program's expected functionality: using loops to draw a rectangle and a triangular pattern by utilizing the given symbol and dimensions.
Transcribed Image Text:### Program Instructions - The program should have a `main` function that reads three inputs: a symbol and two integer values. It will then draw figures similar to the sample run. - The `main` function should call the `drawRectangle` and `drawTriangle` functions. - `drawBar(symbol, length)` function: - Uses a loop to draw a horizontal bar of specified length with the given symbol. - `drawRectangle(symbol, width, height)` function: - Takes three arguments and calls the `drawBar` function. - `drawTriangle(symbol, height)` function: - Takes two arguments and calls the `drawBar` function. - Your output should match the given sample run. ### Sample Run 1 ``` Enter the symbol to draw the shapes: X Enter the width of the shape: 7 Enter the height of the shape: 5 XXXXXXX XXXXXXX XXXXXXX XXXXXXX XXXXXXX X XX XXX XXXX XXXXX XXXX XXX XX X ``` This sample demonstrates the program's expected functionality: using loops to draw a rectangle and a triangular pattern by utilizing the given symbol and dimensions.
```python
# Author: Rahma Seid
# Course: CSCI 1170
# CLA14
# The purpose of this program is

def main():
    shapes(drawRectangle, drawTriangle)

# Draw Rectangle
def shapes(drawRectangle, drawTriangle, drawBar):
    drawRectangle(symbol, width, height)
    symbol = input("Enter the symbol to draw the shape: ")
    while length != drawRectangle():
        width = int(input("Enter the width of the shape: "))  # Check if I should change float to int later
        height = int(input("Enter the height of the shape: "))
        
        for i in range(1, width + 1):
            for space in range(width + i - 1):
                print("", end="")
            for j in range(height):
                print(f"{i} ", end="")
            print()

# Draw Triangle
global rectangle
triangle(symbol, width)
for r in range(rows):
    for c in range(r + 1):
        print("", end=" ")
    print()

# Draw Bar
def shapes(drawBar):
    bar(symbol, length)
    
    return expression
```

### Explanation

This Python script is designed for drawing different shapes such as rectangles and triangles using a specified symbol. Below is a breakdown of its components:

#### Function `main()`
- Calls the `shapes` function with `drawRectangle` and `drawTriangle` as arguments.

#### Function `shapes()`
- Designed to handle drawing of rectangles, triangles, and bars.
- Prompts the user to input a symbol, width, and height for a rectangle.
- Uses nested loops to print a rectangle shape with the specified symbol, width, and height.

#### Drawing Rectangle
- A loop iterates over the width of the rectangle.
- Spaces and symbols are printed to create a rectangle shape.

#### Drawing Triangle
- The script includes a placeholder for a triangle using nested loops.
- The current code suggests a structure but isn't complete for a functional triangle drawing.

#### Drawing Bar
- Contains a placeholder for drawing a bar with the specified symbol and length.

### Note
- There are several code snippets and placeholders (e.g., `global rectangle`, `return expression`) that indicate incomplete or commented-out logic. Further implementation details would be needed for these to be functional and complete the drawing process for triangles and bars.
Transcribed Image Text:```python # Author: Rahma Seid # Course: CSCI 1170 # CLA14 # The purpose of this program is def main(): shapes(drawRectangle, drawTriangle) # Draw Rectangle def shapes(drawRectangle, drawTriangle, drawBar): drawRectangle(symbol, width, height) symbol = input("Enter the symbol to draw the shape: ") while length != drawRectangle(): width = int(input("Enter the width of the shape: ")) # Check if I should change float to int later height = int(input("Enter the height of the shape: ")) for i in range(1, width + 1): for space in range(width + i - 1): print("", end="") for j in range(height): print(f"{i} ", end="") print() # Draw Triangle global rectangle triangle(symbol, width) for r in range(rows): for c in range(r + 1): print("", end=" ") print() # Draw Bar def shapes(drawBar): bar(symbol, length) return expression ``` ### Explanation This Python script is designed for drawing different shapes such as rectangles and triangles using a specified symbol. Below is a breakdown of its components: #### Function `main()` - Calls the `shapes` function with `drawRectangle` and `drawTriangle` as arguments. #### Function `shapes()` - Designed to handle drawing of rectangles, triangles, and bars. - Prompts the user to input a symbol, width, and height for a rectangle. - Uses nested loops to print a rectangle shape with the specified symbol, width, and height. #### Drawing Rectangle - A loop iterates over the width of the rectangle. - Spaces and symbols are printed to create a rectangle shape. #### Drawing Triangle - The script includes a placeholder for a triangle using nested loops. - The current code suggests a structure but isn't complete for a functional triangle drawing. #### Drawing Bar - Contains a placeholder for drawing a bar with the specified symbol and length. ### Note - There are several code snippets and placeholders (e.g., `global rectangle`, `return expression`) that indicate incomplete or commented-out logic. Further implementation details would be needed for these to be functional and complete the drawing process for triangles and bars.
Expert Solution
Step 1

Solution-We have created a program should have a main function that reads three inputs - a symbol and 2 integer values, and we draws the figures similar to the sample run. function main should call the drawRectangle and draw Triangle functions.
 

  • Using a loop in drawBar(symbol, length) function to draw horizontal bar of length with the given symbol. drawRectangle(symbol, width, height) function takes three arguments, then calls the drawBar function.
    draw Triangle(symbol, height) function takes two arguments, then calls the drawBar function. And Your output should match the given sample runs that you can see in given solution-
  • We use an python3 code to create an program .
  • Code is shown below-

# filename :

# Name :

# Summary: The supplied height, width, and symbol are printed for the rectangle and triangle in this application.

 

def drawBar(symbol, length):

    for i in range(length):

        print(symbol,end='')

    print()

   

def DrawRectangle(symbol, width, height):

    for i in range(height):

        drawBar(symbol, width)

       

def DrawTriangle(symbol, height):

    for i in range(height):

        drawBar(symbol, i+1)

    for i in range(height-1,0,-1):

        drawBar(symbol, i)

       

def DrawOptional(symbol, height):

    for i in range(1,height):

        for j in range(height-i):

            print(' ',end='')

        drawBar(symbol, 2*i-1)

    
 

def main():

    symbol = input("Enter the symbol for the shapes: ")

    width = int(input("Enter the width of the shape: "))

    height = int(input("Enter the height of the shapes: "))

    print()

    DrawRectangle(symbol, width, height)

    print()

    DrawTriangle(symbol, height)

   
   

main()

 

Output-

Enter the symbol for the shapes: X
Enter the width of the shape: 7
Enter the height of the shapes: 5
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX

X
XX
XXX
XXXX
XXXXX
XXXX
XXX
XX
X

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Name constants and Literal values
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education