1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erma4kov [3.2K]
3 years ago
14

Write a program named ArrayDemo that stores an array of 10 integers. (Note that the array is created for you and does not need t

o be changed.) Until the user enters a sentinel value, allow the user four options: (1) to view the list in order from the first to last position in the stored array (2) to view the list in order from the last to first position (3) to choose a specific position to view (4) to quit the application.
Computers and Technology
1 answer:
romanna [79]3 years ago
5 0

Answer:

Hi Zoom! Good question. This is particularly useful for learning sorting functions in arrays and user input handling as well. Please find the implementation below.

Explanation:

I have implemented the code in Python 2+. You can save the below code into a file called ArrayDemo.py and then run it from the command line with the command "python ArrayDemo.py". I have declared the demo_array in the code to an array of 10 unsorted integer values to test this. You can change the code if needed to have this array input by user as well and it should work fine.

Note: if you're using Python 3+ then you'll need to change the "raw_input" in the code to just "input" to make it work.

ArrayDemo.py

demo_array = [2,1,3,4,5,7,6,8,10,9]

option = 0

while (option != 4):

 option = raw_input("Enter 1 to view list in ascending order, 2 to view list in descending order, 3 to choose specific poisition to view, 4 to quit the application: ")

 try:

   option = int(option)

   if option == 1:

     sort_by = 'asc'

     print(sorted(demo_array, reverse=False))

   elif option == 2:

     sort_by = 'desc'

     print(sorted(demo_array, reverse=True))

   elif option == 3:

     position = raw_input("Enter specific position to view (0-9): ")

     try:

       position = int(position)

       if position < 0 or position > 9:

         print("Position does not exist")

       else:

         print(demo_array[position])

     except ValueError:

       print("Position does not exist!")

   elif option == 4:

     break

   else:

     break

 except ValueError:

   print("Invalid input!")

You might be interested in
Do you think we could use mathematical operators on string values rather than integers or floats? Explain.
Blizzard [7]

Answer:

Yes and no. For example, you can do this:

print('hi' * 5)

Output:

hihihihihi

HOWEVER, you cannot do mathematical operations on strings. If I have a string "6" and try dividing it by 3, it's not going to work because... it's not an integer. While multiplying strings does work, you cannot actually do real math with strings unless you change them to int or float

4 0
3 years ago
Jennifer frequently uses a few programs on her laptop. Where will she find all the frequently used program icons in her computer
Mkey [24]
Jennifer can find the list of all the frequently used program icons on the left pane of the start menu. Below this list, still on the left pane, all programs installed on her computer will be listed in alphabetical order. This is specific for windows OS.
7 0
3 years ago
Directions: Give the shortcut key for the following commands: 1. Open 2. Save 3. New document 4. Copy 5. Undo 6. Redo 7. Paste 8
stepan [7]

Answer:

Explanation:

1 : Ctrl + X

2 Ctrl + C

3 Ctrl + L

4 Ctrl + V

5 Ctrl + B

6 Ctrl + R

7 Ctrl + I

8 Ctrl + E

9 Ctrl + U

10 Ctrl + Z

11 Ctrl + Y

12 Ctrl + N

End

13 Ctrl + A

Home

14 Ctrl + J

15 Ctrl + 2

16 Ctrl + S

17 Ctrl + 1

18 F12

19 Ctrl + W

-----------

20 Ctrl + K

21 Ctrl + ]

22 Ctrl + (left arrow)

23 Ctrl + (right arrow)

24 Ctrl + [

25 Ctrl + Del

26 Ctrl + 5

27 F1                                                         pls mark me as brainliest and              

                                                                   check all the short cuts

8 0
3 years ago
ICS encourages jurisdictions to use common terminology. Common terminology:
ololo11 [35]
The answer is (a) Uses plain English to allow personnel from different agencies to work together.
ICS or Incident Command System is a systematic tool used for the control, command, and coordination of emergency response. To work together, the ICS allows the use of common terminology and operating procedures.  
3 0
3 years ago
What is the correct order of the phases of the software development process?
Tom [10]

Answer: Planning, Requirements, Design, Build, Document, Test, Deploy, Maintain.

Explanation:

Software Development Life Cycle is the application of standard business practices to building software applications. It's typically divided into six to eight steps / provided above...

6 0
3 years ago
Other questions:
  • True or False? A supervisory control and data acquisition (SCADA) device is a computer that controls motors, valves, and other d
    13·1 answer
  • Which inserted element in an email message displays a graphic from a data source
    15·2 answers
  • Because a vector container uses a dynamically allocated array to hold its elements,
    5·1 answer
  • It is important to create an IT security program structure that aligns with program and organizational goals and describes the o
    6·1 answer
  • An array is stored in contiguous memory locations. You access the individual array value by using the array name followed by the
    6·1 answer
  • A vital step in maintaining an operating system is to regularly do what? Replace the hard drive. Organize the computer’s data. R
    11·2 answers
  • You are the network adminstrator for your company your network consists of two active directory domains research.westsim.local a
    12·1 answer
  • The rate of flow is called
    11·1 answer
  • Write a function isCString which accepts as arguments a const pointer to a char array and an integer for the size of the array
    12·1 answer
  • The ________ is specifically designed for situations requiring a counter variable to control the number of times a loop iterates
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!