In: Computer Science
Using Python programming language, write a LONG piece of code that utilizes the do while function and the switch statement, please do not make It short, thank you.
//both the do-while and switch statement are not available in python so I have written a code that
//mirrors the functionality of do while and switch in python
//Hope this helps. If this is not long enough just comment, I will make it longer
//Leave a like if you feel so :)
//Hope this helps.
def pattern1():
for i in range(1,6):
for j in
range(1,i+1):
print("*",end="")
print()
def pattern2():
for i in range(6,1,-1):
for j in
range(i,1,-1):
print("*",end="")
print()
def pattern3():
for i in range(6,0,-1):
for j in
range(1,i):
print(end=" ")
for k in
range(6,i,-1):
print("*",end="")
print()
def pattern4():
for i in range(1,6):
for j in
range(1,i+1):
print("*",end="")
print()
for i in range(5,1,-1):
for j in
range(i,1,-1):
print("*",end="")
print()
def pattern5():
for i in range(6,0,-1):
for j in
range(1,i):
print(end=" ")
for k in
range(6,i,-1):
print("* ",end="")
print()
def switch(ch):
switcher={
1:"a",
2:"b",
3:"c",
4:"d",
5:"e",
}
return switcher.get(ch,"Wrong Choice")
while True:
choice=int(input("Enter your choice Press 0 to
terminate"))
ch=switch(choice)
if choice==0:
print("Program
Terminated")
break
if ch=="a":
pattern1()
elif ch=="b":
pattern2()
elif ch=="c":
pattern3()
elif ch=="d":
pattern4()
elif ch=="e":
pattern5()
else :
print(ch)
Here is a screenshot of the same problem
OUTPUT