In the file ascii-art.py. you'll find a Python script that prints pictures to the console window,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In the file ascii-art.py. you'll find a Python script that prints pictures to the console window, after open- ing and reading data from a compressed file. The objective of this question is to modify a couple of the functions in this script. You are invited to read the whole script, but you won't have to make changes to the trickiest parts of it. The script reads a text file containing some data which represents an image. There are several example files given for you to try. The data files are encoded using a technique called run-length encoding. Once the data is read from the file, it is decoded, and turned into a 2-dimensional list of single character strings. For example: | [['+', '+', '+'], ['+', '+', ' -'], [' + ', ' - ', ' - ' ]] Each sub-list represents a row: here we have 3 rows and three columns. We call this list of lists an image. When displayed to the console, each character is displayed on a line, row by row: +++ ++- +-- This example is not very artistic, but try out some of the examples! There are 2 functions in the script we will be studying, and they have the following behaviour • flip_updown (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image, but in reverse order; this corresponds to a flip across a horizontal axis. - Returns the new image. - Does not modify the original image. • flip_leftright (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image in the same order, but each row in the new image is reversed; this corresponds to a flip across a vertical axis. - Returns the new image. - Does not modify the original image. We will not be concerned with the other functions in the script. You can read the code, but don't be concerned if the details are a bit tricky. Your task is to rewrite these two functions and change their behaviour to the following: • flip_updown (image) - Its input is a list-of-lists. - Modifies the image so the rows are in reverse order; this corresponds to a flip across a horizontal axis. - Returns None • flip_leftright () - Its input is a list-of-lists. - Modifies the image so the columns are in reverse order; this corresponds to a flip across a vertical axis. - Returns None You'll have to adapt the script that calls these two functions (near the bottom of the file). This is part of the exercise. When you are done, your scripts produce the same images as the original script in the same order. What to hand in: • Hand in your working program in a file called a2q2.py. def flip_updown (image): 1 Purpose: 0 Flip the image upside down Preconditions: image: a list of lists containing single-character strings Post-Conditions: None Return: a new list with the rows in reverse order new_image= [] for row in image: new_image= [row] + new_image return new_image def flip_leftright (image): 3 || || || Flip the image left to right image: a list of lists newimage = [] for row in image: new_row = [] for char in row: new_row [char] + new_row newimage.append(new_row) return newimage In the file ascii-art.py. you'll find a Python script that prints pictures to the console window, after open- ing and reading data from a compressed file. The objective of this question is to modify a couple of the functions in this script. You are invited to read the whole script, but you won't have to make changes to the trickiest parts of it. The script reads a text file containing some data which represents an image. There are several example files given for you to try. The data files are encoded using a technique called run-length encoding. Once the data is read from the file, it is decoded, and turned into a 2-dimensional list of single character strings. For example: | [['+', '+', '+'], ['+', '+', ' -'], [' + ', ' - ', ' - ' ]] Each sub-list represents a row: here we have 3 rows and three columns. We call this list of lists an image. When displayed to the console, each character is displayed on a line, row by row: +++ ++- +-- This example is not very artistic, but try out some of the examples! There are 2 functions in the script we will be studying, and they have the following behaviour • flip_updown (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image, but in reverse order; this corresponds to a flip across a horizontal axis. - Returns the new image. - Does not modify the original image. • flip_leftright (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image in the same order, but each row in the new image is reversed; this corresponds to a flip across a vertical axis. - Returns the new image. - Does not modify the original image. We will not be concerned with the other functions in the script. You can read the code, but don't be concerned if the details are a bit tricky. Your task is to rewrite these two functions and change their behaviour to the following: • flip_updown (image) - Its input is a list-of-lists. - Modifies the image so the rows are in reverse order; this corresponds to a flip across a horizontal axis. - Returns None • flip_leftright () - Its input is a list-of-lists. - Modifies the image so the columns are in reverse order; this corresponds to a flip across a vertical axis. - Returns None You'll have to adapt the script that calls these two functions (near the bottom of the file). This is part of the exercise. When you are done, your scripts produce the same images as the original script in the same order. What to hand in: • Hand in your working program in a file called a2q2.py. def flip_updown (image): 1 Purpose: 0 Flip the image upside down Preconditions: image: a list of lists containing single-character strings Post-Conditions: None Return: a new list with the rows in reverse order new_image= [] for row in image: new_image= [row] + new_image return new_image def flip_leftright (image): 3 || || || Flip the image left to right image: a list of lists newimage = [] for row in image: new_row = [] for char in row: new_row [char] + new_row newimage.append(new_row) return newimage In the file ascii-art.py. you'll find a Python script that prints pictures to the console window, after open- ing and reading data from a compressed file. The objective of this question is to modify a couple of the functions in this script. You are invited to read the whole script, but you won't have to make changes to the trickiest parts of it. The script reads a text file containing some data which represents an image. There are several example files given for you to try. The data files are encoded using a technique called run-length encoding. Once the data is read from the file, it is decoded, and turned into a 2-dimensional list of single character strings. For example: | [['+', '+', '+'], ['+', '+', ' -'], [' + ', ' - ', ' - ' ]] Each sub-list represents a row: here we have 3 rows and three columns. We call this list of lists an image. When displayed to the console, each character is displayed on a line, row by row: +++ ++- +-- This example is not very artistic, but try out some of the examples! There are 2 functions in the script we will be studying, and they have the following behaviour • flip_updown (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image, but in reverse order; this corresponds to a flip across a horizontal axis. - Returns the new image. - Does not modify the original image. • flip_leftright (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image in the same order, but each row in the new image is reversed; this corresponds to a flip across a vertical axis. - Returns the new image. - Does not modify the original image. We will not be concerned with the other functions in the script. You can read the code, but don't be concerned if the details are a bit tricky. Your task is to rewrite these two functions and change their behaviour to the following: • flip_updown (image) - Its input is a list-of-lists. - Modifies the image so the rows are in reverse order; this corresponds to a flip across a horizontal axis. - Returns None • flip_leftright () - Its input is a list-of-lists. - Modifies the image so the columns are in reverse order; this corresponds to a flip across a vertical axis. - Returns None You'll have to adapt the script that calls these two functions (near the bottom of the file). This is part of the exercise. When you are done, your scripts produce the same images as the original script in the same order. What to hand in: • Hand in your working program in a file called a2q2.py. def flip_updown (image): 1 Purpose: 0 Flip the image upside down Preconditions: image: a list of lists containing single-character strings Post-Conditions: None Return: a new list with the rows in reverse order new_image= [] for row in image: new_image= [row] + new_image return new_image def flip_leftright (image): 3 || || || Flip the image left to right image: a list of lists newimage = [] for row in image: new_row = [] for char in row: new_row [char] + new_row newimage.append(new_row) return newimage In the file ascii-art.py. you'll find a Python script that prints pictures to the console window, after open- ing and reading data from a compressed file. The objective of this question is to modify a couple of the functions in this script. You are invited to read the whole script, but you won't have to make changes to the trickiest parts of it. The script reads a text file containing some data which represents an image. There are several example files given for you to try. The data files are encoded using a technique called run-length encoding. Once the data is read from the file, it is decoded, and turned into a 2-dimensional list of single character strings. For example: | [['+', '+', '+'], ['+', '+', ' -'], [' + ', ' - ', ' - ' ]] Each sub-list represents a row: here we have 3 rows and three columns. We call this list of lists an image. When displayed to the console, each character is displayed on a line, row by row: +++ ++- +-- This example is not very artistic, but try out some of the examples! There are 2 functions in the script we will be studying, and they have the following behaviour • flip_updown (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image, but in reverse order; this corresponds to a flip across a horizontal axis. - Returns the new image. - Does not modify the original image. • flip_leftright (image) - Its input image is a list-of-lists. - Creates a new image containing all the rows of the original input image in the same order, but each row in the new image is reversed; this corresponds to a flip across a vertical axis. - Returns the new image. - Does not modify the original image. We will not be concerned with the other functions in the script. You can read the code, but don't be concerned if the details are a bit tricky. Your task is to rewrite these two functions and change their behaviour to the following: • flip_updown (image) - Its input is a list-of-lists. - Modifies the image so the rows are in reverse order; this corresponds to a flip across a horizontal axis. - Returns None • flip_leftright () - Its input is a list-of-lists. - Modifies the image so the columns are in reverse order; this corresponds to a flip across a vertical axis. - Returns None You'll have to adapt the script that calls these two functions (near the bottom of the file). This is part of the exercise. When you are done, your scripts produce the same images as the original script in the same order. What to hand in: • Hand in your working program in a file called a2q2.py. def flip_updown (image): 1 Purpose: 0 Flip the image upside down Preconditions: image: a list of lists containing single-character strings Post-Conditions: None Return: a new list with the rows in reverse order new_image= [] for row in image: new_image= [row] + new_image return new_image def flip_leftright (image): 3 || || || Flip the image left to right image: a list of lists newimage = [] for row in image: new_row = [] for char in row: new_row [char] + new_row newimage.append(new_row) return newimage
Expert Answer:
Related Book For
Molecular Cell Biology
ISBN: 978-1429234139
7th edition
Authors: Harvey Lodish, Arnold Berk, Chris A. Kaiser, Monty Krieger, Anthony Bretscher, Hidde Ploegh, Angelika Amon, Matthew P. Scott
Posted Date:
Students also viewed these programming questions
-
A portion of this question is still incorrect. Cash Budget chooses the accounting period For the Quarter Ending February 28, 2022, January February select an opening cash budget item Beginning Cash...
-
The following background information of this question is repeated in some other questions in this examination: GBA Macao Group, which is a group listed in Shenzhen, was incorporated by two sisters....
-
The goal of this question is to analyze how an organization can help employees gain the new skills required by and for the change effort. For this assignment, you will examine your expectations that...
-
Which is the most effective means of motivating trainees for a training program? a. Pay extra for training time. b. Require the training only for newly hired workers. c. Explain why the training is...
-
A bicycle manufacturer randomly selects 10 frames each day and tests for defects. The numbers of defective frames found over the last 14 days are 3, 2, 1, 3, 2, 2, 8, 2, 0, 3, 5, 2, 0, and 4....
-
Given the information that it has a carboncarbon bond, write a satisfactory Lewis structure for C2H6 (ethane).
-
Use the technique discussed in Section9.4 to develop a GEE approach for zeroinflated Poisson model for count responses in longitudinal studies. Section9.4: 9.4 Marginal Models for Longitudinal Data...
-
The Bartram-Pulley Company (BPC) must decide between two mutually exclusive investment projects. Each project costs $6,750 and has an expected life of 3 years. Annual net cash flows from each project...
-
A figure skater spins at the end of her routine and slows down with an angular acceleration of "0.4" A per second squared. If she initially spun with a frequency of 2.35 Hz, how much time does it...
-
Apple Inc., headquartered in Cupertino, California, designs, manufactures, and markets mobile communication and media devices, personal computers, and portable digital music players and sells a...
-
The Black Death in the fourteenth century decimated European populations by up to 50 percent. Consider a special case of the Romer model presented in class with = A= 1 and assume that only workers...
-
According to equity theory, what are the major considerations that couples take into account in evaluating their levels of satisfaction?
-
Consider the following code: int main() { } char names [4] [5] for (int i=0; i <4; i++) = { "Ant", "Bee", "Cat", "Duck"}; printf("%s ", names[i]); 1. Add another string to the array: kangaroo 2. Make...
-
1. The table below contains information about Company X and Company Y. Company Y 42 2 1.48 Current Market Value (million) Number of Shares (million) Earnings per share Company X 70 4 0.75 a)...
-
If f(x) = 6 + Find f'(4). Find f'(x). Find f"(4). 3 X 6 + 22, find f'(x).
-
For the network-of-queues with probabilistic routing given in Figure 19.3, sup- pose that that each server serves at an average rate of 10 jobs/sec; that is, p= 10, Vi. Suppose that r2 = r3= 1....
-
(a) Define electric flux. Write its S.I. unit.(b) A small metal sphere carrying charge +Q is located at the centre of a spherical cavity inside a large uncharged metallic spherical shell as shown in...
-
Consider the following cash flows in Table P5.5. (a) Calculate the payback period for each project. (b) Determine whether it is meaningful to calculate a payback period for project D. (c) Assuming...
-
Northern blotting, RT-PCR, and microarrays can be used to analyze gene expression. A lab studies yeast cells, Comparing their growth in two different sugars, glucose and galactose. One student is...
-
How is the signal generated by binding of TGF-13 to cellsurface receptors transmitted to the nucleus, where changes in target gene expression occur? What activity in the nucleus ensures that the...
-
What types of genes are transcribed by RNA polymcrases I, II, and III? Design an experiment to determine whether a specific gene is transcribed by RNA polymerase II.
-
Using two CST elements, solve the simple shear problem depicted in the figure and determine whether the CST elements can represent the simple shear condition accurately or not. Material properties...
-
A heat conduction problem is modeled using four onedimensional heat conduction elements, as shown in figure 4.6. All elements are of the same length, \(L=1 \mathrm{~m}\), cross sectional area of...
-
Consider heat conduction in a uniaxial rod surrounded by a fluid. The left end of the rod is at \(T_{0}\). The free stream temperature is \(T^{\infty}\). There is convective heat transfer across the...
Study smarter with the SolutionInn App