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



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
Step by stepSolved in 2 steps with 3 images

- Using Python & import sys Create a program, that has a function that takes a number and prints the number of digits in the number. It should work for numbers with decimals, too.arrow_forwardThe Python print function supports other keyword parameters besidesend. One of these other keyword parameters is sep. What do you thinkthe sep parameter does? Hint: sep is short for separator. Test your ideaeither by trying it interactively or by consulting the Python documentation.arrow_forwardUnder the hood, all Python data types need to be represented as binary integers to be understood by the computer's hardware. You will write a program to peek under the hood at the decimal and binary representation of characters. You will need two new Python functions to perform the conversion that work similar to the built in type conversion functions. The ord() function is used to convert a letter to an integer. The bin() function converts an integer to a string representation of a binary number. To see how these functions work you should play with these functions in the shell, as we do in this example: >>> num = ord('A') >> print(num) 65 >> binary = bin(65) >> print(binary) Øb1000001 Write a program that asks the user for a letter and prints out both the integer and binary representations of the letter. It should ask the user for a character and then output the integer and binary representations of the character. Here is an example of what the output should look like if the user…arrow_forward
- In Python using str(pd.Timestamp.now())[11:13] to get the current number of hours since midnight, write a function that returns a different greeting depending on the time of day. (Hint: use a time argument that defaults to str(pd.Timestamp.now())[11:13] so that you can test your function.)arrow_forwardI can't seem to figure this out.. for python You have a business that cleans floors in commercial space and offices. You charge customers $0.45 per square yard, and some customers require multiple cleanings every month. You need two custom functions for your business. The first function takes a floor's length and width in feet and returns the area in square yards. The second void function takes the area, charge per square yard, and number of monthly cleanings as arguments and prints the cleaning cost. This latter function uses selection logic to print different output for single and multiple monthly cleanings (see Sample Outputs). Use a properly named constant for the charge per square yard, too.arrow_forwardSpecification You must write a script that prints a table of inches and their cquivalent centimcter values. You convert inches to centimeters using the formula cm = inches * 2.54 Centimeter values must be integers. At the top of the table should appear the labels "Inches" and "Centimeters", Under these labels should be a line of dashes. The centimeter values should align with the "Centimeters" label. In other words, it will work in exactly the same way as But it will do this in a different way. The script will create the table using 3 functions which you must write. • print_conversion_table • print_table_header • print_table_line These functions will be called using test code which you will find below. print_conversion_table This function must have the following header def print_conversion_table(min, max): This function will will print the conversion table. It will call print_table_header to print the labels at the top of the table. It will use a for loop to call print_line to print…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





