Goal: This project is designed reinforce the techniques around the following: * Using while loops * Using print statements * Using if statements Description: The program will print nicely formatted...

1 answer below »



Goal:


This project is designed reinforce the techniques around the following: * Usingwhileloops * Usingprintstatements * Usingifstatements


Description:


The program will print nicely formatted tables of numbers. Those numbers will represent integers raised to integer powers between 2 and a chosen upper limit. For instance, the table for the integers up to 4 raised to the powers 1..3 could look like this:



---------- | 1| 1| 1| | 2| 4| 8| | 3| 9|27| | 4|16|64| ==========

Functional Requirements:


This program will be made up of exactly four user-defined functions:



repeated(char, N)


The functionrepeatedtakes two parameters: a string,char, and an integer,N.



repeatedmust meet the following requirements: * It returnsNrepetitions ofchar. * It mustnotuse the string repetition operator (*). * It must not use aforloop to implementrepeated.


These assertions, while not required, may help you:




assert repeated('%', 0) == ''
assert repeated('*', 2) == '**'
assert repeated('$', 4) == '$$$$'



padded(x, width)


The functionpaddedtakes two arguments: an integer,x, and another integer,width.



paddedmust meet the following requirements: * It returns a string of exactlywidthcharacters. * It must userepeatedfor any string repetition needs. * Ifxis too wide to fit in a string ofwidthcharacters, then it should return a string of just asterisks.


These assertions, while not required, may help you:




assert padded(3, 1) == '3'
assert padded(4, 2) == ' 4'
assert padded(12, 4) == ' 12'
assert padded(123, 2) == '**'



power(base, exponent)


The functionpowertakes two arguments: an integer,base, and another integer,exponent.



powermust meet the following requirements: * It must return the integer value ofbaseraised to the power ofexponent. * It must compute this value using a loop. Using the**operator is not allowed. * It maynotassume thatexponentis non-negative. If it is negative,powershould return -1.


These assertions, while not required, may help you:




assert power(3, 0) == 1
assert power(4, 2) == 16
assert power(3, 4) == 81
assert power(3, -3) == -1



print_row(n, max_power, column_width)


The functionprint_rowtakes three integer arguments and prints a string. It does not return anything.


The arguments:




  1. nis the number that is going to be raised to powers in this row of output.


  2. max_powerrepresent the highest power to whichnwill be raised.


  3. column_widthis the number of characters to be used to hold computed values.



print_rowmust meet the following requirements: * It must printmax_powercolumns of output. * It prints a single row. * All columns arewidthwide. * All columns are separated with a|character. * The first and last characters are also the|character. * The first column isnraised to the first power, the second column isnraised to the second power, etc. * You must use thepowerfunction to compute the appropriate values. You must not use the**operator.


Here are some samples:



print_row(4,2,3)will print



| 4| 16|


print_row(5,3,4)will print



| 5| 25| 125|


print_table(max_value, max_power, column_width)



print_tablehas 3 integer arguments: 1.max_valuerepresents the highest value for which the table is going to print a row. 2.max_powerrepresents the maximum power to which any value is raised. 3.column_widthrepresents the width of each column of output (exclusive of the|borders).



print_tablemust meet the following requirements: * It must useprint_rowto print the numeric rows of the table. * It must print an upper and lower border that is the same width as the table. * The upper border is made of-characters. * The lower border is made of=characters. * It should userepeatedas appropriate. It shouldnotuse the string repetition operator (*). * Where it requires looping, it should use awhileloop. It shouldnotuse aforloop.


Here are some samples:



print_table(4, 3, 2)would print



---------- | 1| 1| 1| | 2| 4| 8| | 3| 9|27| | 4|16|64| ==========


print_table(6, 4, 2)would print



------------- | 1| 1| 1| 1| | 2| 4| 8|16| | 3| 9|27|81| | 4|16|64|**| | 5|25|**|**| | 6|36|**|**| =============


main()


Use thismainfunction, and include the final call tomain()




def main():

print_table(4, 3, 2)

print_table(6, 4, 2)

main()


Advice:


Write the functions in the order they were presented above.


Forbidden:


Your program may not use any techniques or Python features forbidden above. Do not use any string-related functionality other than the following: * Concatenation (+) *len(s)to determine the length ofs*str(x)to convert an integer to a string.

Answered Same DayFeb 12, 2022

Answer To: Goal: This project is designed reinforce the techniques around the following: * Using while loops *...

Aditya answered on Feb 13 2022
127 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here