Input ★ 23 Output ***

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 9E: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question
Print grid pattern in python
Assume we need to print a grid structure given the height and width. The grid will be composed of a symbol/character specified by the user.
1. Create a function print_my_grid() that takes height, width, symbol as parameters in that order.
1.1. Loop over the height and inside this loop, create another for loop over the width.
1.2. In the 2nd loop (the loop over the width), print the provided character.
1.3. The function doesn't need to return anything, just prints the grid.
2. In the main program, input from the user a character for the symbol, and 2 integers for the height and width in that order (note
that it is intentionally different from the order of function parameters).
3. The main program should check that both inputs are non-zero positive integers. If yes:
3.1. Call print_my_grid () with the symbol, height and width as arguments. IMPORTANT: Do not call the function inside the
print() statement - the function does not return anything, so using print (print_my_grid(...)) will result in None being
displayed. Calling the function by itself will produce the requested output.
3.2. Otherwise, the program should print "Invalid input, please use positive integers"
Examples
Input
2
3
Output
Hints
• Review CA 4.8.2: Nested loops: Print rectangle.
• Use the Python Tutor to visualize what your code is doing
Transcribed Image Text:Assume we need to print a grid structure given the height and width. The grid will be composed of a symbol/character specified by the user. 1. Create a function print_my_grid() that takes height, width, symbol as parameters in that order. 1.1. Loop over the height and inside this loop, create another for loop over the width. 1.2. In the 2nd loop (the loop over the width), print the provided character. 1.3. The function doesn't need to return anything, just prints the grid. 2. In the main program, input from the user a character for the symbol, and 2 integers for the height and width in that order (note that it is intentionally different from the order of function parameters). 3. The main program should check that both inputs are non-zero positive integers. If yes: 3.1. Call print_my_grid () with the symbol, height and width as arguments. IMPORTANT: Do not call the function inside the print() statement - the function does not return anything, so using print (print_my_grid(...)) will result in None being displayed. Calling the function by itself will produce the requested output. 3.2. Otherwise, the program should print "Invalid input, please use positive integers" Examples Input 2 3 Output Hints • Review CA 4.8.2: Nested loops: Print rectangle. • Use the Python Tutor to visualize what your code is doing
Troubleshooting
if your program displays None, make sure that you are calling the function by itself - do not call it inside the print().
. check that the order of function parameters is exactly as specified in the instructions
422020.2684366.qx3zqy7
LAB
ACTIVITY
4.21.1: LAB: Print Grid Pattern
1 def print_my_grid(...)
2
3
4
5
6
7
8
9 if _name__
10
11
||||||
The function expects
param: var_name (var_type)
The result is ...
||||||
pass
#TODO
"__main__":
main.py
Load default te
Transcribed Image Text:Troubleshooting if your program displays None, make sure that you are calling the function by itself - do not call it inside the print(). . check that the order of function parameters is exactly as specified in the instructions 422020.2684366.qx3zqy7 LAB ACTIVITY 4.21.1: LAB: Print Grid Pattern 1 def print_my_grid(...) 2 3 4 5 6 7 8 9 if _name__ 10 11 |||||| The function expects param: var_name (var_type) The result is ... |||||| pass #TODO "__main__": main.py Load default te
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr