Answer:
The program in Python is as follows:
def count_occur(myList):
freq = {}
for item in myList:
if item in freq:
freq[item] += 1
else:
freq[item] = 1
for item in freq:
print(item," ",freq[item])
Explanation:
This gets the list from the main
def count_occur(myList):
This initializes an empty dictionary
freq = {}
This iterates through the list and count the occurrence of each item
<em> for item in myList:</em>
<em> if item in freq:</em>
<em> freq[item] += 1</em>
<em> else:</em>
<em> freq[item] = 1</em>
This iterates through the dictionary
for item in freq:
This prints each dictionary item and the frequency separated by -
print(item," ",freq[item])
Answer:
1. A We agreed as a group
2. C Communication
3. C Students work independently
4. C Elimination
Explanation:
sorry it wouldnt work unless i typed answers too
Answer:
- import java.util.Arrays;
- import java.util.Scanner;
-
- public class Main {
- public static void main(String[] args) {
- int numArr [] = new int[10];
- Scanner input = new Scanner(System.in);
- System.out.print("Input number: ");
- int num = input.nextInt();
- int i = 0;
- while(num != -1){
- numArr[i] = num;
- i++;
- System.out.print("Input number: ");
- num = input.nextInt();
- }
-
- selectionSortDescendTrace(numArr);
- }
-
- public static void selectionSortDescendTrace(int [] arr){
- for(int i =0 ; i < arr.length - 1; i++){
- int largest = arr[i];
- int largeIndex = i;
-
- for(int j= i + 1; j < arr.length; j++ ){
- if(arr[j] > largest){
- largest = arr[j];
- largeIndex = j;
- }
- }
-
- int temp = arr[i];
- arr[i] = arr[largeIndex];
- arr[largeIndex] = temp;
- System.out.println(Arrays.toString(arr));
- }
- }
- }
Explanation:
The solution code is written in Java.
First, we work on the selectionSortDescendTrace method that takes one input array (Line 21). In the method, we create a nested loops. In the outer loop, we set the current element indexed by i as the largest value and use another variable largeIndex to track the index of largest value (Line 23 -24).
We create inner loop to traverse through the subsequent number after current index-i and compared each of the element by the current largest value (Line 26 - 30). If any of the subsequent element is larger than the current largest value, set the element as largest value and update the largeIndex accordingly (Line 27 - 29).
After completion of inner loop, we swap the position of the current found largest number with the element indexed by current i (Line 33 - 35). Print the partially sorted array (Line 36).
Answer:
The solution code is written in Python 3
- total = 0
- count = 0
- neg = 0
- pos = 0
-
- num = int(input("Enter an integer: "))
-
- while(num != 0):
- total += num
- count += 1
-
- if(num < 0):
- neg += 1
- else:
- pos += 1
-
- num = int(input("Enter an integer: "))
-
-
- print("The number of positives: " + str(pos))
- print("The number of negatives: " + str(neg))
- print("The total is " + str(total))
- print("The average is " + str(total/count))
Explanation:
Firstly, we create four variables, <em>total</em> , <em>count,</em> <em>neg</em> and <em>pos </em>(Line 1- 4). This is to prepare the variable to hold the value of summation of input integer (<em>total</em>), total number of input number (<em>count</em>), total negatives (<em>neg</em>) and total positives (<em>pos</em>).
Next, we prompt user for the first integer (Line 6).
Create a sentinel while loop and set the condition so long as the current input number, <em>num</em> is not equal to zero. the program will just keep adding the current <em>num</em> to total (Line 9) and increment the count by one (Line 10).
if <em>num</em> smaller than zero, increment the <em>neg</em> by one (Line 13) else increment the <em>pos </em>by one (Line 15). This is to track the total number of positives and negatives.
Finally, we can display all the required output (Line 20 - 23) using the Python built-in function <em>print()</em> when user enter 0 to terminate the while loop. The output shall be as follows:
The number of positives: 3
The number of negatives: 1
The total is 5
The average is 1.25
A thank-you note with a business
card enclosed or an e-mail saying how glad you were to meet someone are
examples of contact follow - up. It is another way of
saying that the person is interested to the giver of contact.