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...
-
What are the competitive advantages of using an existing internal audit department over outsourcing the function to a large public accounting firm?
-
Suppose you are the CEO of an American multinational. On your staff and in the U.S. operating divisions of your company are several bright, able, dedicated female executives. They are also ambitious,...
-
What is the scope of the discovery?
-
Your investment department has researched possible investments in corporate debt securities. Among the available investments are the following $100 million bond issues, each dated January 1, 2011....
-
The Long History of Anti-Latino Discrimination in America, you will complete a one-page reflection. Hint: Reflect on the injustices ranging from school segregation to mob violence and mass...
-
Exercise 6.1 Configuring Memory on Paper Objective: a computer is not performing as well as it used to. Windows 10 tool would the technician get the user to open to quickly tell how much RAM is...
-
You are a CFO of Magic Candles Inc. public company with the stocks traded at TSX. You are located in New Westminster, BC. The marketing team of your company has just come up with a new product...
-
Investigate the complex relationship between genotype and phenotype variability in complex traits and diseases, considering the contributions of genetic polymorphisms, gene-environment interactions,...
-
Kenny G wants to buy 100,000 shares of "High Flyer Inc." at the best available price. What type of order should Kenny G's investment advisor place to execute this trade?
-
In the face of your supervisor's directive to eliminate certain sections of findings from the report, how would you apply the Ethical Decision-Making Model to align your response with the NASW Code...
-
Write to Oriental Bank of Commerce, Civil Lines, Bhopal, to make enquiries about the credit standing of Messrs. Rajpal Brothers, Raja Bazar, Bhopal, for a sum of Rs.5,00,000. The party's bankers are...
-
d) The following diagram shows a TTT-diagram of pure iron. Draw a realistic cooling curve after full austenitization in this diagram in order to produce the highest possible content of martensite....
-
The wave function, y(x), of an electron in a potential well of finite depth and width, L, is given by w(x) = Aex for x 0 y(x) =F sin(kx) + G cos(kx) for 0xL y(x) = Be-C for x L a. Given F = G =5, k...
-
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.
-
Compare and contrast statistical and non-statistical (judgmental) sampling. Include in your discussion conditions that might make one approach to sampling more desirable than the other.
-
Consider the data from the previous problem. For each of the sampling methods named: a. Compute the total amount of the transactions sampled and the proportion of the cumulative total the sample...
-
Suppose that an auditor chooses to use a random sampling technique to test additions to fixed assets for the fiscal year for manufacturing company. Walk through the key steps the auditor should...
Study smarter with the SolutionInn App