Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Programming Part 4 Write one last function that combines these other functions together. We will do some simple calculations for the user using our

Python Programming

Part 4

Write one last function that combines these other functions together. We will do some simple calculations for the user using our functions. Consider how you might handle negative values

# function: print_answer # input: 2 numbers that you will peform the arthemetic operation on (both integers) # A plus or a minus symbol (string) # A width value (integer) # processing: Prints the 2 input numbers with the operator between them # followed by an equal sign and the result of the mathematical operation specified by the user # output: does not return anything 

Heres some sample code:

print_answer(5, 2, '+', 5) print() 

Which will generate . . .

 ***** * ***** * ***** * * ***** * * ***** * ***** * ***** ***** ***** ***** * * * * 

You can assume the height of these operators is the same as the height of your numbers (5 units).

I have created all the needed functions I just do not know how to properly combine them for this last part. Pease help! Here are all the functions. (Part I need is at the very bottom)

# function: horizontal_line # input: a width value (integer) # processing: prints a single horizontal line of the desired size # output: does not return anything  def horizontal_line(width): hline = ("*" * width) print(hline) # function: vertical_line # input: a shift value and a height value (both integers) # processing: generates a single vertical line of the desired height. the line is # offset from the left side of the screen using the shift value # output: does not return anything  def vertical_line(shift, height): for i in range(0, height): vline = (" " * shift + "*") print(vline) # function: two_vertical_lines # input: a width value and a height value (both integers) # processing: generates two vertical lines. the first line is along the left side of # the screen. the second line is offset using the "width" value supplied # output: does not return anything  def two_vertical_lines(height, width): for i in range(0, height): vline2 = ("*" + " " * (width-2) + "*") print(vline2) #------------------------------------------------------------------------------------------------  # function: number_0 # input: a width value (integer) # processing: prints the number 0 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_0(width): horizontal_line(width) two_vertical_lines(3, width) horizontal_line(width) # function: number_1 # input: a width value (integer) # processing: prints the number 1 as it would appear on a digital display # using the supplied width value # output: returns nothing   def number_1(width): vertical_line(width-1,5) # function: number_2 # input: a width value (integer) # processing: prints the number 2 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_2(width): if width > 1: horizontal_line(width) vertical_line(width-1,1) horizontal_line(width) vertical_line(0,1) horizontal_line(width) else: print("Invalid width") # function: number_3 # input: a width value (integer) # processing: prints the number 3 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_3(width): if width > 1: horizontal_line(width) vertical_line(width-1,1) horizontal_line(width) vertical_line(width-1,1) horizontal_line(width) else: print("Invalid width") # function: number_4 # input: a width value (integer) # processing: prints the number 4 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_4(width): if width > 1: two_vertical_lines(2, width) horizontal_line(width) vertical_line(width-1,2) else: print("Invalid width") # function: number_5 # input: a width value (integer) # processing: prints the number 5 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_5(width): if width > 1: horizontal_line(width) vertical_line(0,1) horizontal_line(width) vertical_line(width-1,1) horizontal_line(width) else: print("Invalid width") # function: number_6 # input: a width value (integer) # processing: prints the number 6 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_6(width): if width > 1: horizontal_line(width) vertical_line(0,1) horizontal_line(width) two_vertical_lines(1, width) horizontal_line(width) else: print("Invalid width") # function: number_7 # input: a width value (integer) # processing: prints the number 7 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_7(width): horizontal_line(width) vertical_line(width-1,5) # function: number_8 # input: a width value (integer) # processing: prints the number 8 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_8(width): if width > 1: horizontal_line(width) two_vertical_lines(1, width) horizontal_line(width) two_vertical_lines(1, width) horizontal_line(width) else: print("Invalid width") # function: number_9 # input: a width value (integer) # processing: prints the number 9 as it would appear on a digital display # using the supplied width value # output: returns nothing  def number_9(width): if width > 1: horizontal_line(width) two_vertical_lines(1, width) horizontal_line(width) vertical_line(width-1,1) horizontal_line(width) else: print("Invalid width") #--------------------------------------------------------------------------------------------------------------  # function: plus # input: a width value (integer) # processing: prints the plus symbol as it would appear on a digital display # using the supplied width value # output: returns nothing  def plus(width): if width % 2 != 0: vertical_line((width-1)//2,2) horizontal_line(width) vertical_line((width-1)//2,2) elif width % 2 == 0: print(" " * ((width-2)//2), end='') horizontal_line(2) print(" " * ((width-2)//2), end='') horizontal_line(2) horizontal_line(width) print(" " * ((width-2)//2), end='') horizontal_line(2) print(" " * ((width-2)//2), end='') horizontal_line(2) else: print("Invalid width") # function: minus # input: a width value (integer) # processing: prints the operation "-" # output: returns nothing  def minus(width): print() horizontal_line(width) print() # function: equal # input: a width value (integer) # processing: prints the operation "=" # output: returns nothing  def equal(width): print() horizontal_line(width) horizontal_line(width) print() #----------------------------------------------------------------------------------------------------------------  # function: print_answer # input: 2 numbers that you will peform the arthemetic operation on (both integers) # A plus or a minus symbol (string) # A width value (integer) # processing: Prints the 2 input numbers with the operator between them # followed by an equal sign and the result of the mathematical operation specified by the user # output: does not return anything  def print_answer(number1, number2, operator, width): if operator == "+": 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions