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

Write a function in Python to take in a piece of sample text via a long...
Write a function in Python to take in a piece of sample text via a long string (you pick the string) and to output a dictionary with each word as a key and it’s frequency (the number of times it occurred in the original string) as the value. Show an example of your function in use. Be sure to strip out any punctuation.
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"...
Write a function in Python which removes a set of common words from a long piece...
Write a function in Python which removes a set of common words from a long piece of text. Be sure to strip out any punctuation. The common words to be removed are: a, an, as, at, by, for, in, is, it, of, that, this, to, was, will, the These are typical words that are considered to have low semantic value. Process each paragraph provided below individually. Your end result for each paragraph should be a string or list containing the...
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 solve using simple python programming language and make it easy to understand explain your code...
Please solve using simple python programming language and make it easy to understand explain your code as I am a beginner, use appropriate variable names which make the code easy to understand and edit if needed. A subsystem responsible for delivering priority numbers to an automated irrigation system has stopped working and you need to deliver a quick fix that will work until the actual subsystem is fixed by senior developer. As you are the newest addition to the development...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT