168k views
2 votes
1. Write a program that displays a "division table". This is similar to a "multiplication table, but it shows divisions (ratios, fractions, whatever) instead of products.

2. Input two integers, a maximum numerator and a maximum denominator, from the user. Use two input() statements to ask for each value on a separate line.

3. Produce a two-dimensional table, as shown below. The numerators are the row values 1 to maximum numerator, while the denominators are the column values 1 to maximum denominator.

4. Draw lines above and below the table columns

User PixelToast
by
8.3k points

1 Answer

4 votes

Final answer:

To create a division table, take two integer inputs for the maximum numerator and denominator, and then calculate and display each division while formatting the table with lines to separate columns.

Step-by-step explanation:

Creating a Division Table Program in Python

To create a division table program, you would start by requesting two integer inputs from the user. These will represent the maximum numerator and the maximum denominator for the division table. After receiving the inputs, iterate through the range of numbers from 1 to the maximum numerator, and for each of these, iterate again through the range from 1 to the maximum denominator, calculating the division (or ratio) for each combination and displaying the result in a formatted table with lines above and below the column values.

An example of creating such a program in Python is:

max_numerator = int(input('Enter maximum numerator: '))
max_denominator = int(input('Enter maximum denominator: '))
print('+' + '---+' * max_denominator)
for i in range(1, max_numerator+1):
for j in range(1, max_denominator+1):
print(f'| {i/j:0.2f} ', end='')
print('|')
print('+' + '---+' * max_denominator)

This python program displays a division table where each cell shows a formatted division of the numerator by the denominator, rounded to two decimal places. Before and after each row of divisions, a line is printed to visually separate the columns.

User Oowowaee
by
8.2k points