Question

In: Computer Science

Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton...

Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton of the program, and the input and output.

# Initialize list

mylist = [ ]

# Set up loop to put menu on screen

num = 1

while num != 0:

     print(" ")

    print(" ")

    print("            Menu ")

     print ("0 - Quit")

    print ("1 - Add item to list")

    print ("2 - Pop item off list and print it")

    print ("3 - Print list")

     print ("4 - Sort list")

    print ("5 - Reverse list")

    snum = input("Enter choice from menu ")

     num = int(snum)

    print (" ")

   

          Put your if or if-else or if-elif statements here
     (They will be inside the while loop)

       

You should start this lab by entering the above program and saving it as Week5LabA in your Python Programs folder. Then run it to see how it displays the menu. Note that you can enter 0, 1, 2, 3, 4, or 5 in response to the menu choices. Your entry will be assigned to the variable num. Entering a 0 will end the program.

Your other entries (1, 2, 3, 4, or 5 ) should cause something to be done with the list that is called mylist. You will note that mylist has been initialized to the empty list with the mylist = [ ] statement.) For example, if you enter a 1 (value of num is 1), the program should ask you to enter a value to be placed on the list and then append it onto the list. As another example, if you enter a 3 (value of num is 3), the program should print the list using the statement, print(mylist).

The video below shows what the original program (the one I gave you above) should do and how you can enter the if statement for a value of 1 for num.

            View video to get started=>         https://youtu.be/PxTwMpBFFas

The following is a sample execution of the program. The following integers were placed on the list: (Values entered by the user are in red.)

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 1

Enter value to put on list 3

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 1

Enter value to put on list 7

  

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 1

Enter value to put on list 9

The following operations were performed on the list:

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 3

[3, 7, 9]

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 4

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 5

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 3

[9, 7, 3]

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 2

Value popped = 3

            Menu

0 - Quit

1 - Add item to list

2 - Pop item off list and print it

3 - Print list

4 - Sort list

5 - Reverse list

Enter choice from menu 3

[9, 7]

Solutions

Expert Solution

# Initialize list
mylist = [ ]
# Set up loop to put menu on screen
num = 0
print(" ") #printing menu
print(" ")
print("            Menu ")
print ("0 - Quit")
print ("1 - Add item to list")
print ("2 - Pop item off list and print it")
print ("3 - Print list")
print ("4 - Sort list")
print ("5 - Reverse list")
num = int(input("Enter choice from menu ")) #taking choice
while num != 0: #if option is not 0
   if num==1: #if option is 1
       ele=int(input("Enter value to put on list ")) #taking element from user
       mylist.append(ele) #adding element to mylist
   elif num==2: #if option is 2
       if (len(mylist)>=1): #if length of the mylist is greater than 0
           ele=mylist.pop() #pop element
           print("Value popped =",ele) #print popped element
       else: #if there is no element
           print("No value to pop")
   elif num==3: #if option is 3
       print(mylist) #print list
   elif num==4: #if option is 4
       mylist.sort() #sort list
   elif num==5: #if option is 4
       mylist.reverse() #reverse the list
  
   print(" ")
   print(" ")
   print("            Menu ")
   print ("0 - Quit")
   print ("1 - Add item to list")
   print ("2 - Pop item off list and print it")
   print ("3 - Print list")
   print ("4 - Sort list")
   print ("5 - Reverse list")
  
   num = int(input("Enter choice from menu "))

print("Quit")

If you have any doubt comment me.


Related Solutions

Python Programming, Below included the Skeleton, input and output. Could you also include indents in the...
Python Programming, Below included the Skeleton, input and output. Could you also include indents in the solutions. In this programming laboratory you will create a Python program that evaluates the sum of the following mathematical series: Sum = x0 / 0! + x1 / 1! + x2 / 2! + x3 / 3! + … + xn / n!                  The variable x is a real (float) number and the variable n is an integer that can assume values greater than...
JAVA * This is a skeleton file. Complete the functions below. You * may also edit...
JAVA * This is a skeleton file. Complete the functions below. You * may also edit the function "main" to test your code. * * You should not use any loops or recursions. Your code needs to run in * constant time. It is OK if your testing code has loops (like in checkInvariants). * * You must not add fields or static variables. As always, you must not change * the declaration of any method nor the name of...
Java Programming. I'm writing this in an IDE called Eclipse. If you could also use comments...
Java Programming. I'm writing this in an IDE called Eclipse. If you could also use comments to help me understand the code / your way of thinking, I'd highly appreciate your efforts. This needs to use a for each loop, it will generates and return= an array of random 2-digit integers and it also needs to be printed out all on one line, separated by spaces. Program71: Write a program with a custom method that generates and returns an array...
Please use the python and explain. Also please show python. Suppose that a cashier owes a...
Please use the python and explain. Also please show python. Suppose that a cashier owes a customer some change and that the cashier only has quarters, dimes, nickels, and pennies. Write a program the computes the minimum number of coins that the cashier can return. To solve this problem use the greedy algorithm explained below. PROBLEM STATEMENT: Your program should first ask the user for the amount of money he/she is owed (in dollars). You may assume that the user...
We are doing this problem in R software. If you could also show how to do...
We are doing this problem in R software. If you could also show how to do it in that along with the normal work that would be much appreciated. Problem 1 Acid precipitation id linked to the disappearance of sport fish and other organisms from lakes. Sources of air pollution, including automobile emissions and burning fossil fuels, add to the natural acidity of precipitation. The Wisconsin Department of Natural Resources initiated a precipitation monitoring program with the goal of developing...
If you could show work it would be greatly appreciated also, if possible use the template...
If you could show work it would be greatly appreciated also, if possible use the template that I have provided. Thank you, also this is all the question provides me with. SallyMay, Inc., designs and manufactures T-shirts. It sells its T-shirts to brand name clothes retailers in lots of one dozen. SallyMay's May 2013 static budget and actual results for direct inputs are as follows: Static Budget Number of T-shirt lots (1 lot1 dozen) 400 Per Lot of T-shirts: Direct...
Python programming: Instructions: The python program should respond to user input on a command line Below...
Python programming: Instructions: The python program should respond to user input on a command line Below are the four options - if the user input is A, the program will quit -if the user input is B, the program will display the number of times the prompt has been displayed -if the user input is C, will display whatever is stored. -if the user inputs something else, it will store that user input as a string and append it to...
QUESTION 19 You are also able to examine the full skeleton of this same early hominin...
QUESTION 19 You are also able to examine the full skeleton of this same early hominin and observe that it has a very narrow thumb metacarpal head. This observation suggests that: e. This hominin was capable of speech a. This hominin was capable of using tools b. This hominin was not capable of using tools d. This hominin was not bipdeal c. This hominin was bipedal 2 points    Tool-making allowed early hominins to shift from a leaf and fruit-based...
Please show it with python class Node {     int data;     Node left, right;    ...
Please show it with python class Node {     int data;     Node left, right;     public Node(int item)     {         data = item;         left = right = null;     } } public class BinaryTree { // Root of the tree implemented in Node class Node root; Node findLowestCommonAncestor(int node1, int node2) {     return findLowestCommonAncestor(root, node1, node2); } // This function returns pointer to LCA of two given // values node1 and node2. This function assumes that...
Python Programming An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also...
Python Programming An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 and 71 are prime numbers, so 17 and 71 are emirps. Write a program that displays the first 10 emirps.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT