Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

source: [ ### Introduction , , In this assignment you will write some Python statements within this Jupyter Notebook that are answers to the

"source": [ "### Introduction ", " ", "In this assignment you will write some Python statements within this Jupyter Notebook that are answers to the posed programming questions. By saving what you have written into the notebook, and submitting the resulting IPython file via conneX, the teaching team will be able to evaluate your work. ", " ", "You are encouraged to create your own notebooks in order to experiment with programming ideas. Once you have solutions that you wish to submit, they can be copy-and-pasted into this notebook. You should, however, always ensure your Python statements do work by evaluating them within this notebook. ", " ", "** This notebook describes Part B. Part A is in another notebook. **" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Part B: Multiplication table ", " ", "You are to complete a function called ```print_mult_table``` that takes two parameters: ", "* starting value (an integer) ", "* ending value (an integer) ", "and which the prints a multiplication table for the values provided. ", " ", "For example, if: ", "* starting value is 4, and ", "* ending value is 11 ", " ", "then the resulting table printed by a call to ```print_mult_table``` must appear like that below: ", " ", "``` ", " | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 ", " ", " 4 | 16 : 20 : 24 : 28 : 32 : 36 : 40 : 44 ", " 5 | 20 : 25 : 30 : 35 : 40 : 45 : 50 : 55 ", " 6 | 24 : 30 : 36 : 42 : 48 : 54 : 60 : 66 ", " 7 | 28 : 35 : 42 : 49 : 56 : 63 : 70 : 77 ", " 8 | 32 : 40 : 48 : 56 : 64 : 72 : 80 : 88 ", " 9 | 36 : 45 : 54 : 63 : 72 : 81 : 90 : 99 ", " 10 | 40 : 50 : 60 : 70 : 80 : 90 : 100 : 110 ", " 11 | 44 : 55 : 66 : 77 : 88 : 99 : 110 : 121 ", "``` ", " ", "As another example, if: ", "* starting value is 27, and ", "* ending value is 33 ", " ", "then the resulting table printed must appear like that below: ", " ", "``` ", " | 27 | 28 | 29 | 30 | 31 | 32 | 33 ", " ", " 27 | 729 : 756 : 783 : 810 : 837 : 864 : 891 ", " 28 | 756 : 784 : 812 : 840 : 868 : 896 : 924 ", " 29 | 783 : 812 : 841 : 870 : 899 : 928 : 957 ", " 30 | 810 : 840 : 870 : 900 : 930 : 960 : 990 ", " 31 | 837 : 868 : 899 : 930 : 961 : 992 : 1023 ", " 32 | 864 : 896 : 928 : 960 : 992 : 1024 : 1056 ", " 33 | 891 : 924 : 957 : 990 : 1023 : 1056 : 1089 ", "``` ", " ", " ", "We can restrict the values given to the function in a way that eases your work writing the Python solution. ", " ", "1. The starting value must always be less than the ending value. ", "1. The starting value must always be positive. ", "1. The maximum difference between the starting and ending value is 14. ", " ", "If any of the previous three statements is violated by the given parameters, then the function prints an error message. ", " ", "And also: ", "* Any fractional parts to a given value may be ignored. ", " ", "Your program: ", " ", "1. Must complete the definition of ```print_mult_table``` that has been started for you. ", "1. The code for prompting the user is already provided to you, along with the call to ```print_mult_table```." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# The following is known as a 'docstring', and in a later lecture ", "# we will explore how it is normally best used to document a ", "# Python function. ", " ", "''' ", "function: print_mult_table ", " ", "This function prints a multiplication table with row ", "and column headers such that the intersection of row ", "and column pairs, the value of row * column appears. ", "The table is also formatted in such a way that numbers ", "are aligned to the right and given enough space such ", "that the whole table is clearly aligned, column by ", "column and row by row. ", " ", "Input parameters ", "---------------- ", " ", "* start: The number from which multiplication values ", " will begin. ", " ", "* end: The number to which multiplication values will ", " stop. ", " ", " ", "Result value ", "------------ ", " ", "* There is *no* value returned by this function. ", " ", " ", "Output ", "------ ", " ", "* The function outputs to the console the multiplication ", " table corresponding to that needed for the parameter ", " values. If the provided parameters violate certain ", " restrictions, then an error message is printed instead ", " of a multiplication table. ", " ", "''' ", " ", "# ", "# WRITE THE dist_with_accel FUNCTION IMMEDIATELY BELOW. ", "# ", " ", "def print_mult_table(start, end): ", " print (\"Nut 'n Honey\") ", " ", " ", " ", "# DO NOT MODIFY ANYTHING FROM HERE TO THE BOTTOM OF THIS CODE CELL!! ", " ", "# The following main() function prompts the user for required ", "# input and calls the completed function. ", " ", "def main(): ", " start = int(input(\"Start of table \")) ", " end = int(input(\"End of table \")) ", " print_mult_table(start, end) ", " ", "main()"

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

Step: 3

blur-text-image

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions