answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Law Incorporation [45]
2 years ago
8

Exercise 9.1.6: Checkerboard, v1 Spoint

Computers and Technology
1 answer:
AysviL [449]2 years ago
8 0

Answer:

In order to get following pattern, we have to use numpy package.

Following code with work perfectly fine and will print the pattern.

Python code starts as below

*********************************************

<em># Python program to print 8 X 8 alternative 1 and 0's. 3rd and 4th row with all 0's </em>

<em># checkerboard pattern using numpy </em>

<em># We need Following pattern </em>

<em># 0 1 0 1 0 1 0 1 </em>

<em># 1 0 1 0 1 0 1 0 </em>

<em># 0 1 0 1 0 1 0 1 </em>

<em># 0 0 0 0 0 0 0 0 </em>

<em># 0 0 0 0 0 0 0 0 </em>

<em># 1 0 1 0 1 0 1 0 </em>

<em># 0 1 0 1 0 1 0 1 </em>

<em># 1 0 1 0 1 0 1 0 </em>

<em> </em>

<em>import numpy as np </em>

<em> </em>

<em># function to print Checkerboard pattern </em>

<em>def printcheckboard(n): </em>

<em> </em>

<em>        print(" Customized Checkerboard pattern:") </em>

<em>        # create a n * n matrix   </em>

<em>        x = np.zeros((n, n), dtype = int) </em>

<em>        y = np.zeros((n, n), dtype = int) </em>

<em>        # fill with 1 the alternate rows and columns </em>

<em>        x[1::2, ::2] = 1 </em>

<em>        x[::2, 1::2] = 1 </em>

<em>       # fill with 0 the alternate rows and columns </em>

<em>        y[1::2, ::2] = 0 </em>

<em>        y[::2, 1::2] = 0 </em>

<em> </em>

<em>        # print the pattern  for first 3 rows</em>

<em>        for i in range(0,3): </em>

<em>                for j in range(n): </em>

<em>                        print(x[i][j], end =" ") </em>

<em>                print() </em>

<em>        # print the pattern   for next two rows with all 0's</em>

<em>        for k in range(3,5): </em>

<em>                for l in range(n): </em>

<em>                        print(y[k][l], end =" ") </em>

<em>                print() </em>

<em>         # print the pattern  for last 3 rows with alternative 1 and 0.        </em>

<em>        for i in range(5,8): </em>

<em>                for j in range(n): </em>

<em>                        print(x[i][j], end =" ") </em>

<em>                print() </em>

<em> </em>

<em># Calling the function code </em>

<em>n = 8 </em>

<em>printcheckboard(n)</em>

**************************************

End of the Python Code.

Explanation:

In this you have to use Python3.7 and numpy should be installed as well in order to execute the code successfully.

2 D matrix will be created using Python numpy library and checkboard pattern is generated using array slicing.

Here n=8 and it will generate the checkerboard pattern of alternative 0 and 1. However, we need row 4th and 5th as all 0. So we have initialized two arrays matrix as x and y.

Comments in the code is self explanatory.

PS: Please make sure code is edited in IDE so that tabs or space issues can be taken care.

You might be interested in
Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline. Ex:
rosijanka [135]

Answer:

#include <stdlib.h>

#include <time.h>

#include<iostream.h>

int main(void) {

   int seedVal = 0;  

   seedVal = 4;

   srand(seedVal);

  /* Solution*/

  cout<<rand() % 149 + 100<<endl;

  cout<<rand() % 149 + 100<<endl;

  return 0;

}

Explanation:

We start with the required include statements to enable use of srand, rand and time functions. I have also added iostream library to use "cout" function.

After that, the seed is initialized using srand(). And then the two rand functions are called with ranges including and between 100 and 149, and printed out.

6 0
2 years ago
Read 2 more answers
Connie works for a medium-sized manufacturing firm. She keeps the operating systems up-to-date, ensures that memory and disk sto
gizmo_the_mogwai [7]

Answer: Computer operator

Explanation:

Following the information given, we can deduce that Connie is employed as a computer operator. A computer operator is a role in IT whereby the person involved oversees how the computer systems are run and also ensures that the computers and the machines are running properly.

Since Connie keeps the operating systems up-to-date, ensures that memory and disk storage are available, and oversees the physical environment of the computer, then she performs the role of a computer operator.

4 0
2 years ago
The hostel in which you plan to spend the night tonight offers very interesting rates, as long as you do not arrive too late. Ho
faust18 [17]

Answer:

Answered below

Explanation:

// Python implementation

incrementAmount = 5

basePrice = 10

price = 0

arrivalHour = int(input("Enter arrival hour 0-12: ")

if arrivalHour < 0 or arrivalHour > 12:

print ("Invalid hour")

if arrivalHour == 0:

price = basePrice

else:

price = arrivalHour * incrementAmount

totalPrice = price + basePrice

if totalPrice > 53:

totalPrice = 53

print ("Your bill is $totalPrice")

4 0
2 years ago
Go to the Creamy Ice Corporation passage on the next page. Insert the trademark sign after the word “Corporation'' in the first
GuDViN [60]

Answer:

v

Explanation:

because it is

5 0
2 years ago
Write an expression that will cause the following code to print "I am a teenager" if the value of userAge is less than 20. Zyboo
VikaD [51]

Answer:

Replace

if userAge > 20

with

userAge > 19

Explanation:

if userAge > 20  checks if age is 21, 22, 23, 24........

The else condition which prints "I am a teenager" checks if age is 20, 19, 18....

Notice that 20 is inclusive of the else condition; this shouldn't be because for userAge to be less than 20, 20 isn't inclusive

To solve this,

Replace if userAge > 20 with userAge > 19

So that, the else

The else condition which prints "I am a teenager" checks if age is 19, 18, 17, 16....

6 0
2 years ago
Other questions:
  • A(n) _____ is the highest educational degree available at a community college. master bachelor associate specialist
    13·2 answers
  • Mary can view the thumbnails of her presentation slides when she is creating the slides. Which element of the program’s interfac
    5·2 answers
  • Information gets from sensory memory to short-term memory through the process of _________.
    13·1 answer
  • Reading is the process of transferring data, instructions, and information from memory to a storage medium.
    15·1 answer
  • 10) What is the BEST way to rewrite sentence (1) to make it more
    5·2 answers
  • You are on vacation and want to see where all the restaurants and trendy shops are in relation to your hotel. You remember there
    15·1 answer
  • Write a method named removeDuplicates that accepts a string parameter and returns a new string with all consecutive occurrences
    7·1 answer
  • Write a loop to populate the list user_guesses with a number of guesses. The variable num_guesses is the number of guesses the u
    13·1 answer
  • Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar
    12·1 answer
  • Describe how a cell’s content and format attributes are related.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!