Questions
def myLength(mylist):    count = 0    for index in range(len(myList)):        print(myList[index])       ...

def myLength(mylist):
   count = 0
   for index in range(len(myList)):
       print(myList[index])
       count = count + 1
   return count

def myLength2(mylist):
   count = 0
   for element in myList:
       print(element)
       count = count + 1
   return count
  
  
Use these two functions as examples to write your Python function below!

Function 1: Write a function called myCount that takes in two parameters (a list and an item) like this:
def myCount(myList,item):
The function should returns an integer representing how many times the given item is in the given list. Could be from zero up to infinity. You cannot use the list method list.count() to impelement this function.

Function 2: Write a function called myIndex that takes in two parameters (a list and an item) like this:
def myIndex(myList,item):
The function should return an integer representing the index of the first occurrence of the given item in the given list. Returns from zero up to inifinity if the item is found. Returns -1 if it is not in the list.You cannot use the list method list.index() to impelement this function.

Function 3: Write a function called contains that takes in two parameters (a list and an item) like this:
def contains(myList,item):
The function should return True if the item is present in the list and False if it is not. You cannot use the operator "in" to implement this function, like:
if item in myList: #not allowed!
Instead, you should write a loop to look through each element, one at a time, to determine if an item is in the list. This is allowed:
for element in myList: #allowed!

Function 4: Write a function called myInsert that takes in three parameters (a list, an index position, and an item) like this:
def myInsert(myList,index,item):
The function should return a new list consisting of everything from the old list but with the new item inserted at the given index. If index is not valid (less than zero), then the function returns the original list with no changes. You cannot use the list method list.insert() to impelement this function.

In: Computer Science

C++ Questions What is the output of the following pseudocode code: ages = new List Append(ages,...

C++ Questions

What is the output of the following pseudocode code:

ages = new List

Append(ages, 55)

Append(ages, 88)

Append(ages, 66)

Print(ages)

A.

55, 66, 88

B.

55, 88, 66

C.

55, because there is no loop

D.

66, because there is no loop

E.

None of the above.

QUESTION 2

Type the list after the given operations. Each question starts with an empty list. Type the list as: 5, 7, 9

Append(list, 3)
Append(list, 2)
Append(list, 1)
Remove(list, 3)

A.

3, 2

B.

2, 1

C.

1, 2

D.

2, 3

E.

None of the above.

QUESTION 3

Assume 11 element list alist contains the characters in the string "mathematics". What is the sequence of elements after executing the instructions?

list<char> alist;

list<char>::iterator iter;

iter = alist.begin();

iter++;

alist.erase(iter++);

iter++;

alist.erase(iter);

alist.pop_front();

A.

m a t   h e m a t

B.

a t h e   m a t i

C.

m t e a t i c s

D.

t e m a t i c s

E.

None of the above.

QUESTION 4

Given a list with nodes 'Z', 'A', 'B', Sort(list) yields 'A', 'B', 'Z'.

A.

True

B.

False

C.

Lists can not be sorted

D.

Not enough information whether it is ascending or descending.

E.

None of the above.

QUESTION 5

Assume the declaration:

string weekName[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

const int DAYSINWEEK = 7;

list<string>::iterator strIterA, strIterB;

After executing the following instructions, strIterA is the location of day _______.

strIterA = weekList.end();

strIterA--;

strIterA--;

A.

Mon

B.

Wed

C.

Fri

D.

Tues

E.

None of the above.

In: Computer Science

1. List any four types of faults that can occur in power transformers?    2. List any...

1. List any four types of faults that can occur in power transformers?   

2. List any four effects of sustained low power factor on equipment.

3. List any four methods that can be used to improve power factor?

4. List any two economic benefits of power factor correction?

In: Electrical Engineering

Create a mathematical proof to prove the following: Given an integer n, and a list of...

Create a mathematical proof to prove the following:
Given an integer n, and a list of integers such that the numbers in the list sum up to n. Prove that the product of a list of numbers is maximized when all the numbers in that list are 3's, except for one of the numbers being either a 2 or 4, depending on the remainder of n when divided by 3.

In: Math

To meet rising demands for health care, a new form of clinics has begun to emerge:...

To meet rising demands for health care, a new form of clinics has begun to emerge: clinics run by nurse practitioners says the New York Times.

  • About 250 health clinics across America are now completely run by nurse practitioners.
  • These nurses require a master's degree that includes two or three years of advanced training in treating and diagnosing diseases.
  • A new proposal endorsed by the American Association of Colleges of Nursing for 2015 would require nurse practitioners to have a doctorate of nursing practice.

Many of these nurse practitioners are limited in what they can and can't do based on state law. In some states, nurse practitioners are completely free to treat patients and give prescriptions. However, some states won't allow these clinics without at least one trained physician.

These clinics staffed with nurse practitioners offer an avenue for alleviating some of the strain being put on primary care physicians. Indeed, the Affordable Care Act will bring 32 million uninsured people into the health system and there aren't enough primary care physicians to cover them. Furthermore, physicians are poorly distributed, many of them opting to work in urban areas rather than rural towns.

Some critics of having nurse practitioners run clinics argue that the quality of care is compromised for patients.

  • However, data has shown nurse practitioners provide good quality care.
  • One-hundred and eighteen published studies over 18 years found that nurse practitioner-led clinics were at the least equivalent, if not better, when compared to doctor-led clinics.

Moreover, nurse-led clinics are cheaper than traditional doctor-led practices. Furthermore, these clinics are small and don't need a variety of practitioners to keep the clinic at full capacity. Finally, nurse practitioner-led clinics provide patients with an alternative to the emergency room, which results in large savings.

Question:

Discuss your position and analyze how this problem could become a major problem and affect more Americans in the future.

In: Operations Management

ONLY looking for part B!! a. Using C++, define a node structure of the linked list...

ONLY looking for part B!! a. Using C++, define a node structure of the linked list (e.g. value is an integer, next is a node type pointer), construct a linked list of 10 nodes and assign random numbers as the nodes’ values. Use loop to track and print from the first node to the last and output all nodes’ values. Finally, free all memories of the linked list. b. Based on 2.a, (1) define a function which takes the header as parameter, the function will create a new node and assign its value 100; then insert this node at the sixth position of the list; (2) define another function which recursively print the list forwards to verify the result; (3) define the 3rd function which takes the header as parameter, the function will delete the eighth node of the list to keep the linked list having 10 nodes, and (4) define the 4th function which recursively to print the linked list backwards. After creating the four functions, revise your program 2.a, before delete all memories of the list, call the four functions in order to verify the results.

In: Computer Science

Problem 5: Find Smallest Elements In this problem, we will write a function to find the...

Problem 5: Find Smallest Elements

In this problem, we will write a function to find the smallest elements of a list.

Define a function named find_smallest() that accepts two parameters: x and n. The parameter x is expected to be a list of values of the same time, and n is expected to be an either integer, or the value None, and should have a default value of None.

• If n is set to None, then the function should return the smallest element of x (not as part of a list).

• If n is set to a positive integer, the function should return a list consisting of the smallest n elements of list x. If n is greater than the length of the list x, then the entire list x should be returned.

Note that n=None and n=1, should produce similar, but not identical results. Both arguments will select only a single value from the list x, but if n=1 then the function should return a list containing the value, whereas if n=None then the function should simply return the value.

This problem would be challenging to do without using built-in functions, and so you are allowed to do so in this problem. As a hint, I recommend using sorting functions and slicing. However, the list that was provided as an argument to the function should not get sorted or altered as a result of the function being called.

We will now test the find_smallest() function. Create a new code cell to perform the steps below.

Create a list named my_list containing the values 39, 74, 28, 64, 17, 28, 54, 53 (in that order). Print the results of each of the following function calls.

find_smallest(my_list)

find_smallest(my_list, 1)

find_smallest(my_list, 2)

find_smallest(my_list, 5)

find_smallest(my_list, 12)

Let's confirm that the original list has not been altered.

Create a new code cell to print the list my_list.

In: Computer Science

Task #1 Develop a recursive method to reverse a list Develop a method with the prototype...

Task #1 Develop a recursive method to reverse a list Develop a method with the prototype public static void reverse (ArrayList inputList) based on selecting the first list element as the head and the remaining list as its tail. Here is the recursive design. 1) Base case: The problem is trivial when the list size is 0 or 1. 2) Decomposition: For lists with size > 1: a) Extract its head (element) and leave the tail (the input list with the head removed). You can look up the method that does this for the List interface. b) Make a recursive call to obtain the tail reversed. Page 2 of 3 3) Composition: Append the extracted head element to the reversed tail obtain the original list reversed. Task #2 Develop a recursive method to find the maximal element Note that this is not possible unless the list elements are comparable to each other. Java provides a generic Interface for this called Comparable. Based on this, develop a method with the following prototype public static > E max(List inputList) You can use the same problem decomposition technique as in Task #1. Think about how the composition of result should be made. Task #3 Develop a recursive method to sum the list elements Obviously, this is not possible unless the list elements are of numeric type. Develop a recursive summing method with the prototype public static double sum (List inputList) Task #4 Use command line arguments to supply the list elements Use the following main() method: public static void main(String args[]) { ArrayList argList = new ArrayList<>(); ArrayList numericArgs = new ArrayList<>(); for (String s : args) { argList.add(s); try { numericArgs.add(Double.parseDouble(s)); } catch (NumberFormatException e) { System.out.println(e.getMessage() + "is not numeric...skipping"); } } System.out.print("Command line arguments before reversal: "); for (int i=0; i

In: Computer Science

I want a unique c++ code for the following. PLEASE HIGHLIGHT THESE FUNCTIONS WITH COMMENTS ....

I want a unique c++ code for the following. PLEASE HIGHLIGHT THESE FUNCTIONS WITH COMMENTS .

Add the following functions to the class arrayListType: Then, update the main function to test these new functions.

  • removeAll - which removes ALL of the instances of a value in the list
  • min - which returns the minimum value in the list
  • max - which returns the maximum value in the list

arrayListType.h :

#ifndef H_arrayListType
#define H_arrayListType

class arrayListType {
public:
bool isEmpty() const;

bool isFull() const;

int listSize() const;

int maxListSize() const;

void print() const;

bool isItemAtEqual(int location, int item) const;
//Function to determine whether item is the same as the item in the list at the position specified by location.
//Postcondition: Returns true if list[location] is the same as item; otherwise,
// returns false. If location is out of range, an appropriate message is displayed.

void removeAt(int location);
//Function to remove the item from the list at the
//position specified by location
//Postcondition: The list element at list[location] is  removed and length is decremented by 1.
// If location is out of range appropriate message is displayed.

void retrieveAt(int location, int& retItem) const;
//Function to retrieve the element from the list   
//at the position specified by location
//Postcondition: retItem = list[location]
// If location is out of range, an
// appropriate message is displayed.

void clearList();
//Function to remove all the elements from the list After this operation, the size of the list is zero.Postcondition: length = 0;


arrayListType(int size = 100);
//Constructor. The default array size is 100.
//Postcondition: The list points to the array, length = 0, and maxSize = size;

arrayListType (const arrayListType& otherList);
//Copy constructor

~arrayListType();
//Destructor
//Deallocate the memory occupied by the array.
  
void insertAt(int location, int insertItem);
void insertEnd(int insertItem);
void replaceAt(int location, int repItem);
int seqSearch(int searchItem) const;
void remove(int removeItem);

private:
int *list; //array to hold the list elements
int length; //variable to store the length of the list
int maxSize; //variable to store the maximum
//size of the list
};

#endif

arrayListTypeIm.cpp :

#include
#include "arrayListType.h"

using namespace std;

bool arrayListType::isEmpty() const
{
return (length == 0);
} //end isEmpty

bool arrayListType::isFull() const
{
return (length == maxSize);
} //end isFull

int arrayListType::listSize() const
{
   return length;
} //end listSize

int arrayListType::maxListSize() const
{
   return maxSize;
} //end maxListSize

void arrayListType::print() const
{
for (int i = 0; i < length; i++)
cout << list[i] << " ";
cout << endl;
} //end print

bool arrayListType::isItemAtEqual(int location, int item) const
{
if (location < 0 || location >= length)
{
cout << "The location of the item to be removed "
<< "is out of range." << endl;

return false;
}
else
return (list[location] == item);
} //end isItemAtEqual

void arrayListType::removeAt(int location)
{
if (location < 0 || location >= length)
cout << "The location of the item to be removed "
<< "is out of range." << endl;
else
{
for (int i = location; i < length - 1; i++)
list[i] = list[i+1];

length--;
}
} //end removeAt

void arrayListType::retrieveAt(int location, int& retItem) const
{
if (location < 0 || location >= length)
cout << "The location of the item to be retrieved is "
<< "out of range" << endl;
else
retItem = list[location];
} //end retrieveAt

void arrayListType::clearList()
{
length = 0;
} //end clearList

arrayListType::arrayListType(int size)
{
if (size <= 0)
{
cout << "The array size must be positive. Creating "
<< "an array of the size 100." << endl;

maxSize = 100;
}
else
maxSize = size;

length = 0;

list = new int[maxSize];
} //end constructor

arrayListType::~arrayListType()
{
delete [] list;
} //end destructor

arrayListType::arrayListType(const arrayListType& otherList)
{
maxSize = otherList.maxSize;
length = otherList.length;

list = new int[maxSize];    //create the array

for (int j = 0; j < length; j++) //copy otherList
list [j] = otherList.list[j];
}//end copy constructor

//===========
void arrayListType::insertAt(int location, int insertItem)
{
if (location < 0 || location >= maxSize)
cout << "The position of the item to be inserted "
<< "is out of range." << endl;
else if (length >= maxSize) //list is full
cout << "Cannot insert in a full list" << endl;
else
{
for (int i = length; i > location; i--)
list[i] = list[i - 1];   //move the elements down

list[location] = insertItem; //insert the item at
//the specified position

length++;   //increment the length
}
} //end insertAt

void arrayListType::insertEnd(int insertItem)
{
if (length >= maxSize) //the list is full
cout << "Cannot insert in a full list." << endl;
else
{
list[length] = insertItem; //insert the item at the end
length++; //increment the length
}
} //end insertEnd

int arrayListType::seqSearch(int searchItem) const
{
int loc;
bool found = false;

loc = 0;

while (loc < length && !found)
if (list[loc] == searchItem)
found = true;
else
loc++;

if (found)
return loc;
else
return -1;
} //end seqSearch


void arrayListType::remove(int removeItem)
{
int loc;

if (length == 0)
cout << "Cannot delete from an empty list." << endl;
else
{
loc = seqSearch(removeItem);

if (loc != -1)
removeAt(loc);
else
cout << "The item to be deleted is not in the list."
<< endl;
}
} //end remove

void arrayListType::replaceAt(int location, int repItem)
{
if (location < 0 || location >= length)
cout << "The location of the item to be "
<< "replaced is out of range." << endl;
else
list[location] = repItem;
} //end replaceAt

main.cpp :

#include
#include "arrayListType.h"

using namespace std;   
  
int main()
{
arrayListType intList(25);   

int number;
cout << "List 8: Enter 8 integers: ";

for (int count = 0; count < 8; count++)
{
cin >> number;
intList.insertEnd(number);   
}

cout << endl;
cout << "Line 16: intList: ";
intList.print();   
cout << endl;

cout << "Line 18: Enter the number to be "
<< "deleted: ";   
cin >> number;   
cout << endl;

intList.remove(number);

cout << "Line 22: After removing " << number
<< " intList: ";
intList.print();   
cout << endl;

cout << "Line 25: Enter the search item: ";

cin >> number;
cout << endl;

if (intList.seqSearch(number) != -1)   
cout << "Line 29: " << number
<< " found in intList." << endl;
else   
cout << "Line 31: " << number
<< " is not in intList." << endl;   

return 0;
}

In: Computer Science

"PYTHON" Declare a list that is initialized with six of your favorite sports teams. Print out...

"PYTHON"

Declare a list that is initialized with six of your favorite sports teams. Print out the number of teams to the shell. Use a for loop to print out the teams to the shell.

2. a. Declare a sporting goods list, initially with no elements.
b. Use a while loop to prompt the user for a sporting goods item and append the item to the list.
c. Break out of the loop when the user enters exit; do NOT append the word exit to the list.
d. Write a for s in sport_list loop to print out the elements in the list to the shell.
(BONUS) Add code to handle a ctrl-c exit.

3. a. Create a pressure list which initially contains no elements. b. Using the SenseHat, take 25 pressure measurements and store each measurement as a floating-point number in the list. Be sure to have the program sleep for a second or two between each measurement.
c. After recording the measurements, calculate the average of the pressure measurements- use the sum function and display the average on the SenseHat.

4. Allow the user to enter new sporting goods items at a specific index in the sporting goods list. Prompt the user for the index and the new item’s name.

5. Sort the sporting goods list in ascending order. Use a while loop to print out each item in the sporting goods list.

---Allow the user to delete an item from the sporting goods list. Prompt the user for the item’s name.

-- Sort the sporting goods list in descending order. Use a while loop to print out each item in the sporting goods list.


---a. Create a week_tuple and assign the days of the week as strings to the week_tuple.

b. Print out the elements in the week_tuple.

---a. The following list has been declared as follows:
credit_list = [24,3,15]

b. Convert the credit_list to a tuple named credit_tuple.

c. Print out the elements in the credit_tuple.

---a. Write an initialize_list_values function that takes in a number for the number of elements in a list and an initial value for each element. The function creates a new list and appends the elements with the initial value to the new list.

b. Pass in 5 and 3.4 as arguments to the intital_list_values and store the returned list in data_list.

c. Use a loop to print the elements of the data_list.

---a. Create a tuple named inventory_items_tuple which has Raspberry Pi 3, Raspberry Pi 2, and Raspberry Pi Camera Module.

b. Create a tuple named out_of_stock_items_tuple which has Raspberry Pi Zero. (Hint: add a , after “Raspberry Pi Zero”.)

c. Append these two tuples together into the all_items_tuple. Print out each element in the tuple using a for loop and use the len function to determine the number of elements in the tuple.
  

--a. Create a list of lists consisting of three rows and four columns, which were initially set to 0.
b. Prompt the user to initialize each element in the list of lists.
c. Compute the sum of all of the elements in the list. You may use the sum function.
d. Prompt the user to enter a row number and use a loop to calculate the sum of the elements in the row and print out the sum.

In: Computer Science