Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Discover the answers you need from a community of experts ready to help you with their knowledge and experience in various fields. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

Please answer.

For this Code Practice, use the following initializer list, terms:

terms = ["Bandwidth", "Hierarchy", "IPv6", "Software", "Firewall", "Cybersecurity", "Lists", "Program", "Logic", "Reliability"]
Write a sort program to alphabetize the list of computer terms, much like the preceding question. However, this time, define and use a function named swap as part of your solution. The swap function should not be a sort function, but should instead implement the swap functionality used in sorting. This function should swap the elements in the array at each of the indexes by comparing two elements to one another, and swapping them if they need to be in a different alphabetical order.

Your function should take three parameters: the first is the array name, and the second and third are the indexes to swap. Print the terms array before and after it is sorted.

Expected Output
['Bandwidth', 'Hierarchy', 'IPv6', 'Software', 'Firewall', 'Cybersecurity', 'Lists', 'Program', 'Logic', 'Reliability']
['Bandwidth', 'Cybersecurity', 'Firewall', 'Hierarchy', 'IPv6', 'Lists', 'Logic', 'Program', 'Reliability', 'Software']


Sagot :

Answer:

def swap (ar, a, b):

   temp = ar[a]

   ar[a] = ar[b]

   ar[b] = temp

terms = ["Bandwidth", "Hierarchy", "IPv6", "Software", "Firewall", "Cybersecurity", "Lists", "Program", "Logic", "Reliability"]

print(terms)

for i in range(len(terms)):

   for j in (range(i, len(terms))):

       if(terms[i] > terms[j]):

           swap(terms, j, i)

print(terms)

Explanation:

I got 100% on edhesive.

The code practice requires the uses of loops and conditional statements.

Loops are used for repetition of operations, while conditional statements are used for making decisions.

The sort program in Python, where comments are used to explain each line is as follows:

#This defines the swap function

def swap (terms, a, b):

   #This creates a temporary variable

   temp = terms[a]

   #The next two lines swap the elements

   terms[a] = terms[b]

   terms[b] = temp

#This initializes the list

terms = ["Bandwidth", "Hierarchy", "IPv6", "Software", "Firewall", "Cybersecurity", "Lists", "Program", "Logic", "Reliability"]

#This prints the list before sorting

print(terms)

#This calculates the length of the list

n = len(terms)

#This iterates through the list

for i in range(n):

   #This iterates through every other element of the list

   for j in (range(i, n)):

       #This swaps the elements

       if(terms[i] > terms[j]):

           swap(terms, j, i)

#This prints the list after sorting

print(terms)

Read more about sort programs at:

https://brainly.com/question/15263760