Question

In: Computer Science

Using Python programming language, write a LONG piece of code that utilizes the do while function...

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.

Solutions

Expert Solution

//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

      
   


Related Solutions

Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
PUT IN PYTHON LANGUAGE CODE # Write one while-loop that starts at 500 and prints every...
PUT IN PYTHON LANGUAGE CODE # Write one while-loop that starts at 500 and prints every 6th number down to 300 # (i.e., prints 500, 494, 488, . . . etc., but does not print any number lower than 300). # Write one while-loop that starts at 80 and prints every 12h number thereafter, # but does not print any number greater than 210 # Write one while-loop that prints all the numbers from 30 through 70, # except for...
The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
Programming language Python It have to be in Functions with a main function Samuel is a...
Programming language Python It have to be in Functions with a main function Samuel is a math teacher at Hogwarts School of Witchcraft and Wizardry. He loves to give his students multiplication exercises. However, he doesn’t care about the actual operation result but the unit sum of its digits. At Hogwarts School of Witchcraft and Wizardry, they define the unit sum (US) of N as the unit that it is left after doing the sum of all the digits of...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define...
(Python) a) Using the the code below write a function that takes the list xs as...
(Python) a) Using the the code below write a function that takes the list xs as input, divides it into nss = ns/nrs chunks (where nrs is an integer input parameter), computes the mean and standard deviation s (square root of the variance) of the numbers in each chunk and saves them in two lists of length nss and return these upon finishing. Hint: list slicing capabilities can be useful in implementing this function. from random import random as rnd...
Write a python code that calculates π using numpy rand function.
Write a python code that calculates π using numpy rand function.
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should...
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should have #two parameters: a dictionary and a string. The string may be #a key to the dictionary. The value associated with that key, #in turn, may be another key to the dictionary. # #Keep looking up the keys until you reach a key that has no #associated value. Then, return that key. # #For example, imagine if you had the following dictionary. #This one...
Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
Use python programming to write this code and provide a screen short for the code. 2....
Use python programming to write this code and provide a screen short for the code. 2. Write a function that takes one argument (a string) and returns a string consisting of the single character from that string with the largest value. Your function should contain a for loop. You can assume that the input to your function will always be a valid string consisting of at least one character. You can assume that the string will consist only of lower-case...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT