Description
CIS115 Week 4 Lab Multiplication Table in Python
CIS115 Week 4 Lab Overview
Title of Lab: Multiplication Table in Python
Summary
This week’s lab is to create a simple multiplication table using nested loops and if statements.
Prompt the user for the size of the multiplication table (from 2×2 to 10×10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number.
Put a # after any even number in your table (odd numbers will have just a space/nothing after them).
Deliverables
• A source code Python file.
• A Word document containing both source code and the screen print of the program outputs.
Lab Steps
Sample Output:
The output should be something similar to the following.
What size multiplication table would you like? (2 – 10): 1
Invalid entry – Enter a number between 2 and 10
What size multiplication table would you like? (2 – 10): 15
Invalid entry – Enter a number between 2 and 10
What size multiplication table would you like? (2 – 10): 10
— Multiplication Table ( 10 x 10 ) —
        1     2     3     4     5     6     7     8     9    10
—————————————————————————
1Â |Â Â Â Â 1Â Â Â Â Â 2 #Â Â Â 3Â Â Â Â Â 4 #Â Â Â 5Â Â Â Â Â 6 #Â Â Â 7Â Â Â Â Â 8 #Â Â Â 9Â Â Â Â 10 #
2Â |Â Â Â Â 2 #Â Â Â 4 #Â Â Â 6 #Â Â Â 8 #Â Â 10 #Â Â 12 #Â Â 14 #Â Â 16 #Â Â 18 #Â Â 20 #
3Â |Â Â Â Â 3Â Â Â Â Â 6 #Â Â Â 9Â Â Â Â 12 #Â Â 15Â Â Â Â 18 #Â Â 21Â Â Â Â 24 #Â Â 27Â Â Â Â 30 #
4Â |Â Â Â Â 4 #Â Â Â 8 #Â Â 12 #Â Â 16 #Â Â 20 #Â Â 24 #Â Â 28 #Â Â 32 #Â Â 36 #Â Â 40 #
5Â |Â Â Â Â 5Â Â Â Â 10 #Â Â 15Â Â Â Â 20 #Â Â 25Â Â Â Â 30 #Â Â 35Â Â Â Â 40 #Â Â 45Â Â Â Â 50 #
6Â |Â Â Â Â 6 #Â Â 12 #Â Â 18 #Â Â 24 #Â Â 30 #Â Â 36 #Â Â 42 #Â Â 48 #Â Â 54 #Â Â 60 #
7Â |Â Â Â Â 7Â Â Â Â 14 #Â Â 21Â Â Â Â 28 #Â Â 35Â Â Â Â 42 #Â Â 49Â Â Â Â 56 #Â Â 63Â Â Â Â 70 #
8Â |Â Â Â Â 8 #Â Â 16 #Â Â 24 #Â Â 32 #Â Â 40 #Â Â 48 #Â Â 56 #Â Â 64 #Â Â 72 #Â Â 80 #
9Â |Â Â Â Â 9Â Â Â Â 18 #Â Â 27Â Â Â Â 36 #Â Â 45Â Â Â Â 54 #Â Â 63Â Â Â Â 72 #Â Â 81Â Â Â Â 90 #
10 |Â Â Â 10 #Â Â 20 #Â Â 30 #Â Â 40 #Â Â 50 #Â Â 60 #Â Â 70 #Â Â 80 #Â Â 90 #Â 100 #
Hints:
• The outer loop will start each new row.
• The inner loop will control the display of each column in the row.
• Note that to keep the numbers right-aligned, there are different amounts of space before single digit numbers (those less than 10), double digit numbers (those between 10-99), and triple digit numbers (100).
• The row labels can be added to your inner loop (note that there are different amounts of space required after the number in the row labels.
• The column labels should use a separate loop(s) that run before the main outer loop.
• You can continue printing on the same line using end=”” in your print statement. This will come in handy if you want to print several things on one line inside a loop. For example, assuming the value of name is Ada, the following will print “Hello Ada” on one line:
print(“hello “, end=””)
print(name, end=””)
Tips:
• Start early!
• Do the basic table first without worrying about spacing or lining things up, and don’t include row or column headings (add those later).
• Once you get the numbers in the correct position, think about adding the proper amount of space before each number to line things up.
• Once the columns line up, add the #/space for even/odd numbers.
• Once the basic table is working, then add the row and column headings, and finally the main title.
• Test as you go!
Reviews
There are no reviews yet.