Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 4 , CSC 1 0 1 This lab provides additional exercises on conditional reasoning and an introduction to loops. Conditionals modify these files. The

Lab 4, CSC 101
This lab provides additional exercises on conditional reasoning and an introduction to loops.
Conditionals modify these files. The driver provides a mostly complete program but it needs a function to work properly. This is the function that you are to write. The pattern files provide text-based "images". called multiple times; once for each position in the pattern image.
As an example, pattern 00 is made up entirely of repeated 'A' characters. As such, the letter function could be written as follows.
def letter(row, col):
return 'A'
row =0 and col =0. So if the pattern consisted of all 'A' characters but with a single 'G' character in the top-left corner, then the letter function might look as follows.
def letter(row, col):
if (row =0 and col=0):
return 'G'
else:
return 'A'
Multiple Files and All That
name of the pattern). must pass your letter function (by specifying the name as you would a variable). The following code completes the "all A" pattern example discussed above.
import driver
def letter(row, col):
return 'A'
Patterns - What you need to do.
In pattern0. py, write the letter function that will generate the pattern image in pattern00.
When you run this program, you must tell the program which pattern to compare against. You can do so as follows.
python3
pattern00.py pattern00
In
pattern01.py, write the letter function that will generate the pattern image in pattern01.
In pattern02. py, write the letter function that will generate the pattern image in pattern02.
In pattern03. py, write the letter function that will generate the pattern image in pattern03.
In pattern4. py, write the letter function that will generate the pattern image in pattern4.
In
pattern05.py, write the letter function that will generate the pattern image in pattern05.
pattern06
In
pattern06.py, write the letter function that will generate the pattern image in pattern6.
In pattern07. py, write the letter function that will generate the pattern image in pattern07.
Where do I start? pattern01 and try to make pattern01. py! Note that your functions will not print anything. There will be no loops in your functions.
Loops
This part of the lab introduces you to loops in Python. You are asked to edit a small program that uses various loops to accomplish a task.
Code Reading
In the repository you downloaded from GitHub, you will find a file called cubesTable. py. Study the source code to see how it works.
Predict the output from the program if the user enters: 930
Run the code to see if your prediction is correct.
Then predict the output from the program if the user enters: -5530
Run the code to see if your prediction is correct.
Finally predict the output from the program if the user enters: 5,5,-9,3
Run the code to see if your prediction is correct.
Enhancement #1
Enter the value of the first number in the table: -3
First number must be non-negative.
Enter the value of the first number in the table: 2
Enhancement #2
Complete the show_table() function by implementing the code for a for loop that will display the desired table of cubes. For example, if the user enters 45 as the inputs, the table will look like this:
\table[[Number,Cube],[5,125],[6,216],[7,343],[8,512]]
Enhancement #3 the message "Increment must be non-negative.".
Modify the show_table() function so that it takes a third parameter that is the row increment in the table. Modify the counting loop so that it uses the row increment when displaying the table.
Modify the main () function so that it calls get_increment() and passes the result to show_table(). For inputs of 453 the table should now look like this:
\table[[Number,Cube],[5,125],[8,512],[11,1331],[14,2744]]
Hint: To get the numbers to line up nicely (as shown above), I print the first number left justified in a column of six spaces. You can do that using the %-6d modifier, like this:
print("
first,
Enhancement #4- Last one!
Enhance the show_table() function so that it displays the sum of all the cubes in the table on a separate line below the table, in the format "The sum of cubes is: x"(where x is the sum of cubes).
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

explain the need for human resource strategies in organisations

Answered: 1 week ago

Question

describe the stages involved in human resource planning

Answered: 1 week ago