Question

To mimic a real-world programming situation, you are given partially-completed code, written by a former employee you have ju

for each column in range (number of if (each_column % 2) if (each_column % 2) != 0 if (each_row % 2) 0 if (each_row % 2) != 0

To mimic a real-world programming situation, you are given partially-completed code, written by a former employee you have just replaced. Your task is to complete the program he was developing. Fortunately, the former employee's documentation is up-to-date and quite useful Below is the incomplete section of the code, taken from the Python program which is to use Turtle to draw a grid. (In this exercise, a gridis a series of rows, and a rowis a series of boxes or squares.) To draw a grid, each box (square) is drawn starting and finishing at the top left hand corner of the box, heading east (right). A series of boxes drawn in a horizontal line from left to right form a row. Each subsequent row is drawn underneath the previous row. The number of rows to be drawn is stored in the variable: number of rows The number of boxes to be drawn in each row is stored in the variable: number of columns The existing function goto nextboxpos) takes care of repositioning the turtle to where the next box in the row is to be drawn. The existing function goto nextrow.pos) takes care of repositioning the turtle to where the next row is to be drawn Here's the incomplete code. The only missing part is a condition. You can safely assume that all of the other code your predecessor wrote is complete and correct # draw a series of rows of boxes for eachrow in range (number ofrows): draw a series of boxes in a horizontal line for each column in range (number of columns): draw grey box0 else: draw white box () gote next boxpos0 goto next row.pgs0 Complete the code so that the first column is shaded, then every second column is shaded. The image below gives an example of the shading pattern required: NB: The operator returns the remainder after integer division
for each column in range (number of if (each_column % 2) if (each_column % 2) != 0 if (each_row % 2) 0 if (each_row % 2) != 0 if ((each_row each_column) % 2) != 0 go if ((each_row + each_column) % 2) - the code sO ihat the first column is shaded, then every le of the shading pattern required: 0 0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

if (each_column % 2) == 0

Complete code:

# draw a series of rows of boxes
for each_row in range(number_of_rows):
    # draw a series of boxes in a horizontal line
    for each_column in range(number_of_columns):
        if (each_column % 2) == 0:
            draw_grey_box()
        else:
            draw_white_box()
        goto_next_box_pos()
    goto_next_row_pos()

Explanation:-

Suppose we have number_of_columns = 6.
Then, we have to draw grey boxes in column number 0, 2 and 4.
The column numbers above are even numbers and the condition each_column % 2 == 0 checks for even numbers.

  • 0 % 2 = 0
  • 2 % 2 = 0
  • 4 % 2 = 0
Add a comment
Know the answer?
Add Answer to:
To mimic a real-world programming situation, you are given partially-completed code, written by a former employee you...
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
  • The question blank can be filled in with any of these Thanks for your assistance! QUESTION...

    The question blank can be filled in with any of these Thanks for your assistance! QUESTION 1 To mimic a real-world programming situation, you are given partially-completed code, written by a former employee you have just replaced. Your task is to complete the program he was developing. Fortunately, the former employee's documentation is up-to-date and quite useful. (He must have been a QUT student!) Below is the incomplete section of the code, taken from the Python program which is to...

  • Using java : In this exercise, you need to implement a class that encapsulate a Grid. A grid is a useful concept in crea...

    Using java : In this exercise, you need to implement a class that encapsulate a Grid. A grid is a useful concept in creating board-game applications. Later we will use this class to create a board game. A grid is a two-dimensional matrix (see example below) with the same number of rows and columns. You can create a grid of size 8, for example, it’s an 8x8 grid. There are 64 cells in this grid. A cell in the grid...

  • Please do in C please. Edit sliding.c. Comments on code would be nice. Thank you. Here is main.c #include "sliding.h" #include <malloc.h> #include <stdlib.h> //Prints grid in row...

    Please do in C please. Edit sliding.c. Comments on code would be nice. Thank you. Here is main.c #include "sliding.h" #include <malloc.h> #include <stdlib.h> //Prints grid in row major order. Tries to ensure even spacing. void print_grid(int * my_array, int rows, int cols){ int i,j; for(i=0; i<rows; i++){ for(j=0; j<cols; j++){ if(my_array[i*cols + j]!=-1){ printf(" %d ", my_array[i*cols + j]); } else{ printf("%d ", my_array[i*cols + j]); } } printf("\n"); } } int main(int argc, char *argv[]) { int seed,rows,cols;...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Help due in a few hours I need to clean this up can you help me clean up this code to accomplish the same task but with fewer lines/ more elegantly. Thank you! My code for the function is below: int...

    Help due in a few hours I need to clean this up can you help me clean up this code to accomplish the same task but with fewer lines/ more elegantly. Thank you! My code for the function is below: int is_valid_board(int board[9][9]) { int array[10]; int array_box[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; int i, j, k, x, y; //rows=i, columns =j for (i=0; i<9; i++) { //Reset test array for (x = 0; x...

  • EX16 XL _CH01_GRADER ML2 HW - Real Estate Sales Report 1.3 Project Description: You own a...

    EX16 XL _CH01_GRADER ML2 HW - Real Estate Sales Report 1.3 Project Description: You own a small real estate company in Indianapolis. You track the real estate properties you list for dlients. You want to analyze sales for selected properties. Yesterday, you prepared a workbook with a worksheet for recent sales data and another worksheet listing several properties you listed. You want to calculate the number of days that the houses were on the market and their sales percentage of...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's...

    You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's Life is played on a matrix of cells, kind of like a chess board but theoretically extending infinitely in every direction. Each individual cell in the matrix can either be alive or dead. A live cell in the matrix is shown in our simulation by printing an asterisk (*) to the screen. A dead cell is shown by leaving that area of the matrix...

  • Instructions This assignment has to be completed by each student individually. NO COLLABORATION I...

    I need help creating a class diagram for this please: I am not sure what more you want? it has 2 classes at least Connect4 and Connect4TextConsole. Instructions This assignment has to be completed by each student individually. NO COLLABORATION IS ALLOWED Submit YourASURitelD ProjectDeliverable2.zip compressed folder should contain the following files following This the 1. 2. Connect4.java 〔Game Logic Module) Connect4TextConsole.java (Console-based Ul to test the gamel 3. JavaDoc documentation files index.html and all other supporting files such as.cs5...

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