Question

Write a function draw_T in functions.py, which receives three parameters: width, height and symbol. The first two parameters are assumed to be integers and the third is a single character string. You don’t need to validate the type of the given parameters. The function returns no values. The function uses the given parameters to draw a T shape, such that the parameter width controls the upper bar, and height controls the middle vertical bar. The parameter symbol, controls which symbol is to be used in the drawing. In order to make a drawing, the following conditions should be satisfied: • The value of width should be an odd number at least equal to 1 • The value of height should be at least 1 In case one of the above two conditions is violated, the function should print an error message and returns without printing a shape. The error messages are either 'Error(draw_T): Invalid width' or 'Error(draw_T): Invalid height'

Sample Run: (User input is in green) Enter string1: AA Enter string1: CC Enter string2: BB Enter string2: DD Enter value of n

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

CODE IN PYTHON:

def draw_T(width, height, symbol):
    if width < 1 or width % 2 == 0:
        print("Error(draw_T): Invalid width")
        return
    if height < 1 :
        print("Error(draw_T): Invalid height")
        return
    #print top horizontal bar
    for i in range(width):
        print(symbol, end=" ")
    print("")
    for i in range(1, height):
        for j in range(0, width//2):
            print(" ", end=" ")
        print(symbol)

width = int(input("Enter width : "))
height = int(input("Enter height : "))
symbol = input("Enter symbol : ")
draw_T(width, height, symbol)

INDENTATION:

def draw_T(width, height, symbol): if width < 1 or width % 2 == 0: print(Error(draw_T): Invalid width) return if height < 1

OUTPUT:

Enter width : 9 Enter height : 7 Enter symbol : # # # # # # # # # # Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Write a function draw_T in functions.py, which receives three parameters: width, height and symbol. The first...
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
  • Write a main function that gets a number, which represents the height and a character/symbol and...

    Write a main function that gets a number, which represents the height and a character/symbol and draws a triangle of the character by calling the functions defined in 1, 2, and 3 above. SAMPLE RUN Enter a number between 3 and 7:2 Invalid value Enter a number between 3 and 7:5 Enter either # or *:% Invalid symbol Enter either # or *: & Invalid symbol Enter either # or *:#

  • Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...

    Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it  listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 language:Python

  • Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...

    Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it  listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 Language Python

  • Use Python 3.7 to Write a function called volume_of_box() that takes three parameters (the length, width,...

    Use Python 3.7 to Write a function called volume_of_box() that takes three parameters (the length, width, and height of the box) and returns the volume of the box. Then, use that function in a program which prompts the user to enter the dimensions of a box and returns the volume. Your program should include input validation to ensure that the values entered are positive and should be able to accept float values. Many thanks for all your time and effort...

  • Question 4.4: Write an overloaded function of function area with 3 (float) parameters. This function should...

    Question 4.4: Write an overloaded function of function area with 3 (float) parameters. This function should calculate and print out the product of the 3 parameters. Question 4.4: Write the main function to test question 4.1, 4.2, 4.3, 4.4. Your main function should ask if the user want to calculate the area of a rectangle or a circle or a triangle then print out the result accordingly. (Use switch structure). For example: Please enter (r) for rectangle, (t) for triangle,...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Write the letter of the correct answer on the first page. Control of entry into the...

    Write the letter of the correct answer on the first page. Control of entry into the cell cycle is essential. Unicellular eukaryotes that enter into it too soonyw have the necessary energy to complete it, leading to their demise, whereas in multicellular eukaryotes usually leads to cycle are controlled by proteins, problems with the genes that code for these proteins are a commorn source of error. These genes fall into two broad groups: 33 uncontrolled cellular division 32 Since the...

  • Please answer 1c, use MATLAB, and paste your entire script in your answer so that I...

    Please answer 1c, use MATLAB, and paste your entire script in your answer so that I can copy and paste to see if it works. Problem #1 400g triangle square pentagon hexagon Figure 1 For a closed geometric figure composed of straight lines (Figure 1), the interior angles in the figure must add to (n-2)(180) where n is the number of sides. Required Tasks a) Write a script that prompts the user to select from one of the following shapes:...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

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