Question

In: Computer Science

Create a program (or set of programs) which accomplish the following for each complex data type...

Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary):

  • create the item with at least 4 elements
  • Append an element
  • Remove an element
  • Insert an element in the middle somewhere
  • Append another array of the same data type
  • Append another array of a different data type (for example, if you have a dictionary, append a set or tuples

And do the following:

  • Output the results after each step.
  • Report and explain any errors (if a line of code generates an error, comment it out along with a comment on what the error was and your reasons for that error)
  • Create a range of negative numbers
  • Create a range of positive even numbers
  • Insert a range into each data type that would allow it

Turn in:

  • All source code
  • Execution of your program(s)
  • Explanation of each error you ran into

PYTHON

Solutions

Expert Solution

1. Using List

  • Insert 4 elements in the list

  • Appending a new element

  • Insert an element in the middle

  • Appending another array of the same datatype

  • Appending another array of different datatype

  • remove an element from a list

2. Using tuple

  • Insert 4 elements in the tuple

  • Insert another element in the tuple

You can't insert a new element in an existing tuple because it's tuple property that it's unchangeable. And if you want to add a new element then, we can create a new tuple and rename it as the previous tuple.

  • Insert an element at the given index

As we know tuple is unchangeable so, we can't enter a new element in the tuple but, if we really want to do so then we can create a new tuple through slicing and add a new element at a given index and rename it as the previous tuple.

  • Insert another element of the same datatype

As I said above tuples are unchangeable so we can't modify the existing tuple. But if we really want to add a tuple in a tuple then we can create a new tuple and rename it.

  • Insert another element of different datatype

As in previous cases, we can't modify the existing tuple but, we can create a new one and rename it

3. Using Set

  • Insert four elements in a set

  • Insert another element in a set

  • Insert an element at the given index

We can't add an element in the middle of the set. As there is no predefined function and we can't use slicing in the set.

  • Insert a set into a set

Since set elements must be hashable, and lists are considered mutable, you cannot add a list to a set. You also cannot add other sets to a set. You can, however, add the elements from lists and sets as demonstrated with the update method.

  • Insert a tuple into a set

  • Remove given element

4. Using frozenset

As its name suggests, we can't modify it once it's declared. but there are some basic set operations like union, intersection, disjoint, etc.. So it's not possible to modify it.

  • Insert four elements into frozenset

It's NOT POSSIBLE to insert, remove, and modify it. So other cases are irrelevant.

5. Using Dictionary

  • Insert four elements

  • insert new element

  • insert at given index

We can't add a new key in between of existing dictionary but, we can create a new dictionary and perform changes in that dictionary

  • insert a dictionary into the dictionary

  • insert an element of another datatype

  • remove an element in the dictionary


Related Solutions

Create a program (or set of programs) which accomplish the following for each complex data type...
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary): create the item with at least 4 elements Append an element Remove an element Insert an element in the middle somewhere Append another array of the same data type Append another array of a different data type (for example, if you have a dictionary, append a set or tuples And do the following: Output the results after each step. Report and explain...
In this program, you'll create a program that utilizes an enumerated data type to manipulate the...
In this program, you'll create a program that utilizes an enumerated data type to manipulate the array.   Here are the requirements: Write a program that contains an enumerated data type named Letters.    In the declaration, include the following three enumerators: ALPHA, BETA, DELTA. Then, create an array of integers three elements long. The array should be initialized to 0 using a 1-element initialization list. Instead of using integers as subscripts, use the enumerators from your enumerated data type to assign...
Use of an Irrevocable Life Insurance Trust can accomplish which of the following? A. Create a...
Use of an Irrevocable Life Insurance Trust can accomplish which of the following? A. Create a vehicle to avoid Generation Skipping Transfer Tax B. Make proceeds available to the surviving spouse C. Ensure that proceeds will be included in the probate and gross estate of grantor D. Shelters cash contributed for premiums from taxation up to the annual exclusion amount
Create programs in Visual Basic which perform each of the following: Explain the different design choices...
Create programs in Visual Basic which perform each of the following: Explain the different design choices (syntax) for option in each language Document the programs using Flowcharts Each programs source code must be included – label each with the language used a) Nested two-way selection statements b) Multiple-way selection statement c) Iterative Statements – Counter controlled and Logic controlled d) After the Counter Controlled Iterative successfully completes – Display “This was a success” on the screen.
Create programs in Visual Basic which perform each of the following: Explain the different design choices...
Create programs in Visual Basic which perform each of the following: Explain the different design choices (syntax) for option in each language Document the programs using Flowcharts Each programs source code must be included – label each with the language used a) Nested two-way selection statements b) Multiple-way selection statement c) Iterative Statements – Counter controlled and Logic controlled d) After the Counter Controlled Iterative successfully completes – Display “This was a success” on the screen.
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
Using the following lines of data, create a temporary SAS data set called ThreeDates. Each line...
Using the following lines of data, create a temporary SAS data set called ThreeDates. Each line of data contains three dates, the first two in the form mm/dd/yyyy descenders and the last in the form ddmmmyyyy. Name the three date variables Date1, Date2, and Date3. Format all three using the MMDDYY10. format. Include in your data set the number of years from Date1 to Date2 (Year12) and the number of years from Date2 to Date3 (Year23). Round these values to...
Create comprehensive audit programs for the Sales and Receivables So each audit program would include the...
Create comprehensive audit programs for the Sales and Receivables So each audit program would include the following components: Audit steps for tests of controls, balances, transactions, analytical procedures, etc. as well as other considerations such as sample size and sample methodology.
Write program logic or pseudocode to create 3 small programs that do the following: The first...
Write program logic or pseudocode to create 3 small programs that do the following: The first should compute the sum of 2 given integers. The second should multiply the 2 integers. The third should triple the sum of the 2 integers.
The following is a set of tree-set test programs that show the following outputs: Switch to...
The following is a set of tree-set test programs that show the following outputs: Switch to ArrayList, LinkedList, Vector, TreeMap, and HashMap to display similar output results. Results: Tree set example! Treeset data: 12 34 45 63 Treeset Size: 4 First data: 12 Last Data: 63 Removing data from a tree set Current tree set elements: 12 34 63 Current tree set size :3 Tree set empty. Example code import java.util.Iterator; import java.util.TreeSet; public class TreeDemo2 { public static void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT