Question

USING PYTHON 3. For this question, you will build three helper functions and one main function....

USING PYTHON 3.

For this question, you will build three helper functions and one main function. All four functions must work together to draw the letter ‘H. Every line of code written should be inside of a function.

Here are the function specifications:

1) Helper function (given):

def draw_edges(symbol, width):

print(symbol + " "*(width-2) + symbol)

2) Helper function:

draw_H(symbol, width, height):

This function will draw an "H" symbol, given the symbol, width, and height. This function must call the draw_edges function at least once.

3) Helper function:

get_width()

This function will prompt the user for an odd integer 3 or greater and error check the input to ensure it is valid.

4) Main function:

draw_letter(symbol)

The main function must call get_width to obtain the width, calculate letter height (width+2), and then must call draw_H appropriately to draw the ‘H’ with the information given.

What is the line of code that will execute this task given these functions?

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

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

#prints symbol followed by width-2 spaces and then symbol again
def draw_edges(symbol, width):
    print(symbol + " "*(width-2) + symbol)

#This function will draw an "H" symbol, given the symbol, width, and height
def draw_H(symbol, width, height):
    #looping for height number of times
    for i in range(height):
        #if this is middle row, printing width number of symbols
        if i==height//2:
            print(symbol*width)
        else:
            #otherwise calling draw_edges()
            draw_edges(symbol,width)

#This function will prompt the user for an odd integer 3 or greater and error check the
# input to ensure it is valid.
def get_width():
    n=0
    #looping as long as n is less than 3
    while n<3:
        #asking and reading n
        try:
            n=int(input("Enter width (3 or above): "))
        except:
            #in case of exception, setting value of n to 0
            n=0
        #after a loop, if n is less than 3, printing error, asking again
        if n < 3:
            print('Invalid width, please try again!')
    #finally returning n if it is valid
    return n

#this will draw the letter H with given symbol
def draw_letter(symbol):
    #reading width, calculating height
    width=get_width()
    height=width+2
    #drawing H by calling draw_H()
    draw_H(symbol,width,height)


#the below line of code will draw letter H with symbol 'H' after reading width from user
draw_letter('H')

#output

Enter width (3 or above): -2 Invalid width, please try again! Enter width (3 or above): habsjs Invalid width, please try agai

Add a comment
Know the answer?
Add Answer to:
USING PYTHON 3. For this question, you will build three helper functions and one main function....
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
  • Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions...

    Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions you created. Only use one value of r and h for all the function. Ask the user for the r and h in the main() as an input, and h for all the functions. You should put the functions for areas in a separate file. ​ For example, firstDigtec7ze Write a function e digits n) (returning the number of digits in the argument returning...

  • Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main(). You will write...

    Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main(). You will write the code for the above functions. Both magic functions (magic-sequential() and magic-binary()) will look for a magic index in a given sorted list of distinct integers. A magic index in a list myList[0 ... n-1] is defined to be an index i such that myList[i] = i . Both functions receive the list as a parameter and return an integer: either the magic index,...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...

    Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is. Please remember the following two guidelines: unless the purpose of the function is to generate output DO NOT write to the screen within the function unless the purpose...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import...

    I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2):     product = num1 * num2     result = a.add(product, product)     return result     def main():     num1 = 4     num2 = 3     answer = multiply(num1, num2)     print("The answer is", answer) if __name__ == "__main__":     main() arithmetic module: def add(x, y):     z = x + y     return z Refer to Code...

  • ON PYTHON: ''' Design the functions described below. RECALL: With functions that do not return a...

    ON PYTHON: ''' Design the functions described below. RECALL: With functions that do not return a value and print a result to the console, to test you must call the function, run it and visually inspect the result for correctness. With functions that return a value, use the print_test function to provide feedback of the test results at the command line. The print_test function is implemented for you at the bottom of this file. RECALL: floating point arithmetic can lose...

  • PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

    PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI() This function prints out your name and lists any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one...

  • PYTHON please help! im stuck on this homework question, THANK YOU! please follow the rules! Give...

    PYTHON please help! im stuck on this homework question, THANK YOU! please follow the rules! Give a recursive python implementation of the following function: def check_Decreasing_Order(lissy): Given lissy, a python list of integers, the above function will return True if lissy is sorted in decreasing order, otherwise it will return false. For example, print(check_Decreasing Order([100,50,8, -2])) True print(check_Decreasing_Order([108,50,8,2,35])) False Implementation Requirements: 1. Your implementation must be recursive. 2. If you need more parameters, you may define new functions or helper...

  • program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks,...

    program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks, and combining their use to solve a larger problem. Also to practice documenting functions. Degree of Difficulty: Moderate Your task is to compute the cost of renovating the flooring in a rectangular room. This includes replacing the carpet and and the baseboards. Your task is to write a Python program that calculates and the cost of the renovation. To accomplish this, you will need...

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