Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sample Program Execution: he purpose of program: (not shown here) ease c nenu le

ID: 3736139 • Letter: S

Question

Sample Program Execution: he purpose of program: (not shown here) ease c nenu lease choose fron the menu : Draw a single bar of synbol Draw a single bar of symbol Print numbers from n tom Draw a rectangle Draw a right triangle Quit Print numbers fron n to m : Draw a rectangle : Draw a right triangle : Quit er your choice: 2 nter the first bound: 2 nter your choice: ter the second bound:7 is an invalid choice is the sequence: 3456 lease choose from the nenu : Draw a single bar of symbol ease choose fron the menu Draw a single bar of symbol Print numbers from n to m Draw a rectangle Draw a right triangle : Print numbers from n tom : Draw a rectangle : Dr : Quit aw a right triangle Quit nter your choice: 7 nter your choice: nter the symbol for the rectangle: # nter the width of the rectangle: 6 nter the height of the rectangle: 3 is an invalid choice ease choose fron the nenu Draw a single bar of symbol is your rectangle: Print numbers from n to Draw a rectangle Dr aw a right triangle Quit lease choose from the nenu nter your choice: nter the symbol for the bar: nter the length of the bar: 7 : Draw a single bar of symbol : Print numbers fro n to m : Draw a rectangle is your bar Draw a right triangle Quit lease choose fron the nenu nter your choice: nter the symbol for the rectangle: ter the height of the rectangle: 5 Draw a single bar of symbol Print nunbers from n tom Draw a rectangle Draw a right triangle Quit is your triangle nter your choice: 2 nter the first bound: 7 nter the second bound: 2 : Draw a single bar of synbol Print numbers fron n to m numbers are 65432 Draw a rectangle : Draw a right triangle : Quit ter your choice:

Explanation / Answer

import sys

def printPurpose():
print("#****************************************************************************")
print("Funtion Purpose : prints a horizontal bar of symbol which is length long")
print("Parameters : symbol(to fill) and length(of the horizontal bar)")
print("Pre-Condition : symbol and length have appropriate values , length > 0")
print("Post-Condition : a Horizontal bar has been printed")
print("#****************************************************************************")
  
def displayMenu():
print("please choose from the menu : ")
print("=================================")
print("1. Draw a single bar of symbol")
print("2. print numbers from n to m")
print("3. Draw a rectangle")
print("4. Draw a right traingle")
print("5. Quit")
print("=================================")

def drawBox(symbol,length):
for i in range (0,length):
print(symbol,end="")
print("")

def printSequence(first,second):
print("")
print("The numbers are : ")
if(first<=second):
for i in range(first,second+1):
print(i,end=" ")
else:
for i in range(first,second-1,-1):
print(i,end=" ")
print("")
  
def printRectangle(symbol,width,height):
print("")
print("Here is your rectangle : ")
for i in range(0,height):
drawBox(symbol,width)
print("")

def printTriangle(symbol,height):
print("")
print("Here is your right triangle : ")
for i in range(0,height):
drawBox(symbol,i+1)
print("")
  
def main():
printPurpose()
while(1):
displayMenu()
print("Enter your choice : "),
opt = int(input())
if(opt>5 or opt<1):
print("")
print(str(opt) + " is an invalid option")
print("")
if(opt==1):
print("Enter the symbol for the bar : ",end="")
symbol = input()
print("Enter the length of the bar : ",end="")
length = int(input())
print("")
print("Here is your bar : ")
drawBox(symbol,length)
print("")
if(opt==2):
print("Enter the first bound : ",end="")
first = int(input())
print("Enter the second bound : ",end="")
second = int(input())
printSequence(first,second)
if(opt==3):
print("Enter the symbol for the rectangle : ",end="")
symbol = input()
print("Enter the width of the rectangle : ",end="")
width = int(input())
print("Enter the height of the rectangle : ",end="")
height = int(input())
printRectangle(symbol,width,height)
if(opt==4):
print("Enter the symbol for the right triangle : ",end="")
symbol = input()
print("Enter the height of the rectangle : ",end="")
height = int(input())
printTriangle(symbol,height)
if(opt==5):
sys.exit()
  
if __name__ == '__main__':
main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote