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
Yuri [45]
3 years ago
12

Define a function typeHistogram that takes an iterator ""it"" (representing a sequence of values of different types) and builds

a histogram showing how many values of each type appears in the next n elements in the sequence.
Computers and Technology
1 answer:
Alexeev081 [22]3 years ago
3 0

Answer:

def typeHistogram(it,n):

   d = dict()

   for i in it:

       n -=1

       if n>=0:

           if str(type(i).__name__) not in d.keys():

               d.setdefault(type(i).__name__,1)

           else:

               d[str(type(i).__name__)] += 1

       else:

           break

   return list(d.items())

it = iter([1,2,'a','b','c',4,5])

print(typeHistogram(it,7))

Explanation:

  • Create a typeHistogram function that has 2 parameters namely "it" and "n" where "it" is an iterator used to represent a sequence of values of different types while "n" is the total number of elements in the sequence.
  • Initialize an empty dictionary and loop through the iterator "it".
  • Check if n is greater than 0 and current string is not present in the dictionary, then set default type as 1 otherwise increment by 1.
  • At the end return the list of items.
  • Finally initialize the iterator and display the histogram by calling the typeHistogram.
You might be interested in
Select the correct answer
DIA [1.3K]

Answer:

b

Explanation:

scan the images with 72DPI

5 0
3 years ago
The lower the weight of your water rocket the better it will fly. Why?
Gwar [14]

Yo, Big Shaq, the one and only

Man's not hot, never hot

Skrrat, skidi-kat-kat

Boom

Two plus two is four, minus one that's three, quick maths

Everyday man's on the block, smoke trees

See your girl in the park, that girl is a uckers

When the ting went quack-quack-quack, you man were ducking (you man ducked)

Hold tight, Asnee (my brotha), he's got the pumpy (big ting)

Hold tight, my man (my guy), he's got the frisbee

I trap, trap, trap on the phone, movin' that cornflakes

Rice Krispies, hold tight my girl, Whitney (my G)

On the road doin' ten toes, like my toes (like my toes)

You man thought I froze, I see a peng girl, then I pose (chilin')

If she ain't on it, I ghost, hah, look at your nose

6 0
3 years ago
The ___________________ Act makes it illegal to deactivate or otherwise disable any antipiracy technologies including DRM techno
arsen [322]

Answer:

Digital Millennium Copyright Act

Explanation:

Digital Millennium Copyright Act (DMCA) is a protection placed on creative works online and gave content owners the authority to have their contents removed from websites who use it without permission, the act prohibits the reselling and giving away of commercial programs, contents or devices, violating the act is criminal

5 0
4 years ago
Ask the user how many high scores they want.
Alex

Answer:

Check the explanation

Explanation:

As per requirement submitted above kindly find below solution.

Here new console application in C# is created using visual studio 2019 with name "HighScoreApp". This application contains a class with name "Program.cs".Below is the details of this class.

Program.cs :

//namespace

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

//application namespace

namespace HighScoreApp

{

class Program //C# class

{

//entry point of the program , Main() method

static void Main(string[] args)

{

//declaring variable to store number of score

int numberOfScores = 0;

//using while loop

while(numberOfScores<=0)

{

//asking user number of high scores

Console.WriteLine("Enter number of high scores : ");

//reading input

numberOfScores = int.Parse(Console.ReadLine());

}

//declaring array with number of scores

int[] scores = new int[numberOfScores];

//asking user high scores using for loop

for (int i = 0; i < scores.Length; i++)

{

//asking high scores

Console.WriteLine("Enter score "+(i+1)+" : ");

//reading score

scores[i] = int.Parse(Console.ReadLine());

}

Console.WriteLine();//used for new line

Console.WriteLine("High Scores -Unsorted");

//call function to print each element

PrintArray(scores);

//call method to sort the array elements

scores = SortArrayHighToLow(scores);

Console.WriteLine();//used to print new line

Console.WriteLine("High Scores-Sorted");

PrintArray(scores);//call method to print array elements

Console.SetCursorPosition(0, Console.WindowHeight - 1);

Console.WriteLine("Press ENTER to continue....");

Console.ReadLine();

}

//method to print the array

public static void PrintArray(int [] scoresArray)

{

//using for loop , print each score

for (int i = 0; i < scoresArray.Length; i++)

{

Console.WriteLine(scoresArray[i]);//print each high score

}

}

//method to sort the array

public static int [] SortArrayHighToLow(int[] scoresArray)

{

Array.Sort(scoresArray);

return scoresArray;

}

}

}

==================================

Output :Run application using F5 and will get the screen as shown below

Kindly check the below Screenshot for Output :Program.cs

6 0
3 years ago
A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set
Vanyuwa [196]

Answer:

from functools import reduce

def mean(mylist):

   score = reduce(lambda x,y: x + y, mylist)/ len(mylist)

   return score

def median(mylist):

   sorted(mylist)

   list_len = len(mylist) % 2

   i = round(len(mylist)/2)

   x = len(mylist)//2

   if list_len == 0:

       median = (mylist[x] + mylist[x+1]) / 2  

   else:

       median = mylist[i]

   return median

def mode(mylist):

   unique = set(mylist)

   unique = list(unique)

   collector = [mylist.count(key) for key in unique]

   maxi = max(collector)

   loc = collector.index(maxi)

   return unique[loc]

def main():

   scores = input( 'Enter list of numbers: ').split(",")

   scores = [int(score) for score in scores]

   

   operation = input('Enter operation: ')

   operator = ['mean', 'median', 'mode']

   

   for x in iter(list, 0):

       if operation in operator:

           break

       print("Invalid operation: ")

       operation = input('Enter operation')

   

   index_loc = operator.index(operation)

   

   if index_loc == 0:

       return mean(scores)

   elif index_loc == 1:

       return median(scores)

       #return np.median(scores)  can be used of the defined function

   elif index_loc == 2:

       #return stats.mode(scores)[0]  can be used of the defined function

       return mode(scores)

print( main( ) )

Explanation:

The main python function calls conditionally three statistical functions namely mean, median and mode. It prompts for user input for a list of integer numbers and a function name name to return the corresponding result.

8 0
3 years ago
Other questions:
  • Please help!
    10·1 answer
  • Technological improvements have allowed people to inhabit a wider variety of places more easily. Please select the best answer f
    6·2 answers
  • Write an interface, PointingDevice, containing: an abstract method, getXCoord that returns an int an abstract method, getYCoord
    14·1 answer
  • Having one password for all accounts is an easy way to remember passwords, but it will expose you to what risk?
    15·1 answer
  • Which two pieces of information must be provided when saving a file for the first time in Wordpad?____.
    8·1 answer
  • You use the ____ button if you want to specify subtotals or other calculations within the wizard.
    12·1 answer
  • When a program is adapted to run on multiple processors in a multiprocessor system, the execution time on each processor is comp
    10·1 answer
  • Which are the correct commands to create and run an ReactJS project?
    10·1 answer
  • What should you consider when using a wireless keyboard with your home computer
    15·1 answer
  • Your child has broken the RJ-45 port of your laptop by sticking clay into it and there are no wireless networks available in you
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!