Answered step by step
Verified Expert Solution
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 CSC
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 textbased "images". called multiple times; once for each position in the pattern image.
As an example, pattern is made up entirely of repeated characters. As such, the letter function could be written as follows.
def letter col:
return
row and col So if the pattern consisted of all A characters but with a single character in the topleft corner, then the letter function might look as follows.
def letterrow col:
if row and col:
return
else:
return
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 letterrow col:
return
Patterns What you need to do
In pattern py write the letter function that will generate the pattern image in pattern
When you run this program, you must tell the program which pattern to compare against. You can do so as follows.
python
patternpy pattern
In
patternpy write the letter function that will generate the pattern image in pattern
In pattern py write the letter function that will generate the pattern image in pattern
In pattern py write the letter function that will generate the pattern image in pattern
In pattern py write the letter function that will generate the pattern image in pattern
In
patternpy write the letter function that will generate the pattern image in pattern
pattern
In
patternpy write the letter function that will generate the pattern image in pattern
In pattern py write the letter function that will generate the pattern image in pattern
Where do I start? pattern and try to make pattern 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:
Run the code to see if your prediction is correct.
Then predict the output from the program if the user enters:
Run the code to see if your prediction is correct.
Finally predict the output from the program if the user enters:
Run the code to see if your prediction is correct.
Enhancement #
Enter the value of the first number in the table:
First number must be nonnegative.
Enter the value of the first number in the table:
Enhancement #
Complete the showtable function by implementing the code for a for loop that will display the desired table of cubes. For example, if the user enters as the inputs, the table will look like this:
tableNumberCube
Enhancement # the message "Increment must be nonnegative.".
Modify the showtable 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 getincrement and passes the result to showtable For inputs of the table should now look like this:
tableNumberCube
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 modifier, like this:
print
first,
Enhancement # Last one!
Enhance the showtable 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: where is the sum of cubes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started