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
Based on the net income of the shop, the sales staff at Francesca's Fashions receive performance bonuses. In periods of declinin
Lena [83]

<u>Answer</u>:   A : LIFO

<em>LIFO stands for Last in First Out</em>

<em>LIFO accounting is method which is applied in United States. All the other countries use FIFO (First in First Out). </em>

<u>Explanation:</u>

<em>A LIFO method believes that the last entered item in the inventory will be first item which would have been sold.</em> It is significant to track the inventory costs, in order to take the business expenses into account and those can be deducted from the business tax.

Suppose there is an entry like below

<em>Batch 1: 1500 products produced Costs 4000 </em>

<em>Batch 2: 2000 products produced Costs 2500 </em>

<em>Batch 3: 3200 products produced Costs 3500 </em>

So LIFO assumes that Batch 3 is the first entry.

3 0
3 years ago
As you are analyzing a website, what is one indicator of relevance?
Artyom0805 [142]
How often individuals promote a site, not sure about this one. It’s either that one or how often individuals select a site
5 0
3 years ago
New trends, tools, and languages emerge in the field of web technology every day. Discuss the advantages of these trends, tools,
ikadub [295]

Answer:

Explanation:However, with the emergence of several new web development technologies, tools, frameworks, and languages in the last few years, it has now become quite .

7 0
3 years ago
4.7 Code Practice: Question 2
Bess [88]

for x in range(56, 71):

   print(x, end=" ")

I hope this helps!

8 0
3 years ago
If 15 bits are sent in 3 seconds then Bits intervalis__________
Olegator [25]

Answer:

<u>Bit Interval is 0.2 seconds</u>

Explanation:

To Answer this question we first need to know what a Bit Interval is. The definition of this term is the following,

<u>Bit Interval:</u> is the amount of time that it takes to send a single bit of data

Now that we know this information we can calculate the amount it takes to send 1 bit of data by dividing the 3 seconds by the 15 bits sent.

\frac{3}{15} = 0.2 seconds

So it takes 0.2 seconds to send 1 bit of data meaning the <u>Bit Interval is 0.2 seconds</u>

<u></u>

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

7 0
4 years ago
Other questions:
  • 1. You want to schedule a weekly analysis for the Windows servers in your data center. The command should run as a scheduled job
    15·1 answer
  • Consider a simple application level protocol built on top of udp that allows a client to retrieve a file from a remote server re
    15·2 answers
  • Zach wants to learn a programming language to create games and applications. this programming language will also create web appl
    12·2 answers
  • 1. Of which of the following is a box an example?
    10·2 answers
  • Liam is a hacker who tries to access Wi-Fi signals while driving his car. What type of wireless network attack is this?
    9·1 answer
  • Implement (in Java) the radixSort algorithm to sort in increasing order an array of integer positive keys. public void radixSort
    13·1 answer
  • Describe how learning can be accessed in your class?​
    14·1 answer
  • which of the following is a likely problem for a driver in an urban area? A. fame animals on the roads B.not finding a gas stati
    6·1 answer
  • IF YOU WANT NICELY ENGLISH MUSIC ADD MY W.h.a.t.s.A.p.p nomber <br>+60 199094836​
    5·1 answer
  • How many times is the body of the loop executed?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!