Concept explainers
Python!!
Learning Objective
- Use nested loops to achieve numerous repeating actions for each repeating action
- Practive print() function inside the loop
- Work with specific `end="?" parameter of print() function
Instruction
Assume we need to print a grid structure given the height and width.
-
Create a function print_my_grid that takes height and width as parameters
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 " * "
-
Input from the user 2 integers height and width
-
Check that both inputs are non zero positive integers. If yes:
3.1 Call print_my_grid with height and width as arguments
3.2 Otherwise, print "Invalid input, please use positive integers"
The code I should complete:
def print_my_grid(height, width)
'''Write your code here'''
pass
if __name__== "__main__":
'''Write your code here'''
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images
- How do I complete the code to get a similar output in the image? Fibonacci Sequence Coding using Memoization C PROGRAM HELP: - Create the mfib() function to calculate Fibonacci using memoization - Also create the initMemo() function to clear out memoization table(s) at the beginning of each mfib() run The output of the program will record the relative amount of time required from the start of each function calculation to the end. Note the speed difference between fib and mfib! Turn in your commented program and a screen shot of the execution run of the program. Do not be alarmed as the non-memoization Fibonacci calls take a long time to calculate, especially the higher values. Be patient. It should finish. Given Code: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> #include <time.h> // max number of inputs #define MAX_FIB 200 // result of call to fib function unsigned long long result; //loop variable int i; //…arrow_forwardC#(Sharp): I made my code and design below. Anybody can help me some correction and add some design button and code. "Need to make C# step by step design and code "Calculator where make a calculator program that can do add, subtract, multiply, divide and square root. It should have a memory save/restore function for one number. There should be a way to set the number of fraction digits displayed". Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace AktCalc { public partial class Form1 : Form { string last = ""; bool minus = false; bool plus = false; bool divide = false; bool multiply = false; string memory = ""; public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (textBox1.Text.Contains(",")) { return; } else { textBox1.Text += ","; } } private void…arrow_forwardC++ Coding: Nested Loops Create a constant DIM. Set DIM to 7, and use a nested loop to display the following square matrix output. Output Example: - - - X - - -- - - X - - -- - - X - - -X X X O X X X- - - X - - -- - - X - - -- - - X - - -arrow_forward
- Quèstion 25 By default the compiler is always responsible to set the step-size for a loop variable in a counting iterative statement. True Falsearrow_forwardDefine a function named get_pattern_number() which promps the user to input an integer which is between 0 and 8 (inclusive). If the user enters an invalid value, the function continues to prompt the user to enter the number (using a while loop) until the number entered is valid. The function returns the valid number. For example: Test Input Result print (get_pattern_number()) 50 Enter a number (0-8): 50 Enter a number (0-8): 25 25 -12 Enter a number (0-8): -12 Enter a number (0-8): -1 -1 9 Enter a number (0-8): 9 2 Enter a number (0-8): 2 2 Enter a number (0-8): 8 value = get_pattern_number() 8 print (value) 8 print (type(value))arrow_forwardHow do I complete the code to get a similar output in the image? Fibonacci Sequence Coding using Memoization C PROGRAM HELP: - Create the mfib() function to calculate Fibonacci using memoization - Also create the initMemo() function to clear out memoization table(s) at the beginning of each mfib() run The output of the program will record the relative amount of time required from the start of each function calculation to the end. Note the speed difference between fib and mfib! Turn in your commented program and a screen shot of the execution run of the program. Do not be alarmed as the non-memoization Fibonacci calls take a long time to calculate, especially the higher values. Be patient. It should finish. Given Code: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> #include <time.h> // max number of inputs #define MAX_FIB 200 // result of call to fib function unsigned long long result; //loop variable int i; //…arrow_forward
- C PROGRAM Create a c program that will convert number figures into words 1. You can use user-defined functions, string, array, and loops 2. Maximum input limit is 10000.00 Sample output (bold letters is for input) Enter amount in Peso: 143.50 You just entered P145.50 equivalent to One Hundred Forty Three and Fifty Centavos. Do you want to convert another amount? [Y|N]: Narrow_forwardprogram4_2.pyWrite a program that uses a while loop to enable the user to enter any number of positive integers. The loop should end when a sentinel value of 0 (zero) is entered. The program should then report the sum of the even integers and the sum of the odd integers.arrow_forwardCreate a function using a "while" loop. The function asks the user to input a number between 10 and 20. If the number is not within the specified limits, the user must change his/her input until he/she enters the correct value.arrow_forward
- Turtle Drawing with Loops Objective: To make a drawing using turtle graphics and nested loops Requirements: -Your program should ask the user at least two questions, and use the answers to help make the drawing. -Your program must have at least one pair of nested loops (a loop inside of a loop) to do some of the drawing -Your drawing cannot be made up only of rotated polygons coming from the center of the screen like we did in class. -Please write a new program for this assignment - don't use code from any in-class exercises. -For example, your program could draw a field of flowers, or you could draw a repetitive square pattern like you might see on a rug.arrow_forwardPYTHON QUESTION ASSIGNMENT REQUIREMENTS This assignment requires a dictionary of state abbreviations and their capital cities. The abbreviations are the keys and the state capitals are the values. Start by entering data for any four states of your choice. Then, report this count but use a function to get the count. Use a while loop to add more abbreviations and capitals. The loop should continue until the user presses Enter when prompted for an abbreviation. Inside the while loop: If the state entered is already in the dictionary, report its capital. If it is not in the dictionary, prompt the user to enter the capital for that state and add it to the dictionary After the while loop ends: Report again the count of the number of states in the dictionary. Using another loop and the items() method, display all the state abbreviations and their capitals. In the same Python program write this code, although it has nothing to do with the states code. Using a dictionary…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