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]
2 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]2 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
Create the following new exceptions: PokemonException, which extends the Exception class. It must have a no-parameter constructo
slamgirl [31]

Answer:

public class PokemonException extends Exception {

public PokemonException() {

super();

}

}

public class KantoPokemonException extends PokemonException {

public KantoPokemonException() {

super();

}

}

public class JohtoPokemonException extends PokemonException {

public JohtoPokemonException() {

super();

}

}

public class HoennPokemonException extends PokemonException {

public HoennPokemonException() {

super();

}

}

public class SinnohPokemonException extends PokemonException {

public SinnohPokemonException() {

super();

}

}

public class UnovaPokemonException extends PokemonException {

public UnovaPokemonException() {

super();

}

}

public class KalosPokemonException extends PokemonException {

public KalosPokemonException() {

super();

}

}

public class AlolaPokemonException extends PokemonException {

public AlolaPokemonException() {

super();

}

}

public class GalarPokemonException extends PokemonException {

public GalarPokemonException() {

super();

}

}

Explanation:

  • A separate Java file needs to be created for each of the following exception.
  • Inside the constructor, call the super() method to inherit all the properties of a parent class.
6 0
2 years ago
Write an application that determines which, if any, of the following files are stored in the folder where you have saved the exe
Elza [17]

Answer:

Here is the JAVA application that determines which if any of the following files are stored in folder where you have saved the exercises created.

import java.nio.file.*;   // used to manipulate files and directories

import java.nio.file.attribute.*;  //used to provide access to file and file attributes

import static java.nio.file.AccessMode.*;  // provides access modes to test the accessibility of a file

import java.io.IOException;  //for exception handling

class FindSelectedFiles {

public static void main(String[] args) { //start of main function

   Path f1 = Paths.get("/root/sandbox/autoexec.bat"); //creates Path object f1 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f2 = Paths.get("/root/sandbox/CompareFolders.java");  //creates Path object f2 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f3 = Paths.get("/root/sandbox/FileStatistics.class");   //creates Path object f3 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   Path f4 = Paths.get("/root/sandbox/Hello.doc"); //creates Path object f4 using Paths.get() method and this instance contains the file name and directory list used to construct the specified path

   int count=0; //used to count the number of files found  

try{  // used to define a code chunk to be tested for errors

 f1 = Paths.get("/root/sandbox/autoexec.bat");  // Converts a path string when joined form a path string to a Path

 System.out.println(f1);  //prints the file

     /* getFileSystem method is used to return the file system that created this Path object f1 and checkAccess Verifies access and throws exception if something is wrong

 f1.getFileSystem().provider().checkAccess(f1);  

 System.out.println(f1 +" File Exists\n");  //if file exists then displays this message

 count++;  }  //adds 1 to the count of number of files found

 catch (IOException e) {  //a code chunk to be executed if error occurs in the try part

  System.out.println("File Doesn't Exist\n"); }  //if file not found displays this message

   

try{  //works same as above try block but for 2nd folder and object f2

 f2 = Paths.get("/root/sandbox/CompareFolders.java");

 System.out.println(f2);

 f2.getFileSystem().provider().checkAccess(f2);

 System.out.println(f2 +" File Exists\n");

 count++;  }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

try{  //works same as above try block but for 3rd folder and object f3

 f3 = Paths.get("/root/sandbox/FileStatistics.class");

 System.out.println(f3);

 f3.getFileSystem().provider().checkAccess(f3);

 System.out.println("File Exists\n");

 count++; }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

try{  //works same as above try block but for 4th folder and object f4

    f4 = Paths.get("/root/sandbox/Hello.doc");

    System.out.println(f4);

 f4.getFileSystem().provider().checkAccess(f4);

 System.out.println(f4 +" File Exists\n");

 count++; }

 catch (IOException e) {

  System.out.println("File Doesn't Exist\n"); }

   

   System.out.println(count+" of the files exist");  }  } //displays the number of files found

Explanation:

If you want to directly pass the file name as argument to Paths.get() method then you can use the following code:

   Path f1 = Paths.get("autoexec.bat");

   Path f2 = Paths.get("CompareFolders.java");

   Path f3 = Paths.get("FileStatistics.class");

   Path f4 = Paths.get("Hello.doc");

The program determines if any, of the files from autoexec.bat, CompareFolders.java, FileStatistics.class, and Hello.doc. are stored in the folder. If a file is found then the program displays the message File exists and add 1 to the count variable each time a file is found. If all the files are found then the program returns the count as 4 otherwise the program display the number of files found by displaying the computed final value of count in the output. Lets say all the files are found then the output of the above program is:

autoexec.bat                                                                                                                                                   autoexec.bat File Exists  

                                                                                                                                                      CompareFolders.java                                                                                                                                            CompareFolders.java File Exists                                                      

                                                                                                                                                         FileStatistics.class                                                                                                                                           File Exists                                                                                        

                                                                                                                                                     Hello.doc                                                                                                                                                      Hello.doc File Exists  

   

4 of the files exist    

8 0
2 years ago
Your program has a two-dimensional array, scores. You are implementing your array with lists. Each member in the array is a pair
Viefleur [7K]

Answer:

scores.append(6,2)

Explanation:

This is a complicated question because in theory, scores.insert can also add values, but I am sure that the only line of code that would work is scores.append(6,2)

7 0
2 years ago
Antiglare screens are sometimes called ____.
yaroslaw [1]
Simply a glare screen, because it clearly states what it protects one against, I guess.
8 0
3 years ago
Finally, Su uses the last slide of her presentation as a summary slide. She wants to make sure the text she types automatically
Alex777 [14]

Answer:

Format Shape pane

Text Options

Shrink text on overflow

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Websites that are designed to adapt gracefully to any screen size use a technique called
    5·1 answer
  • When troubleshooting a desktop motherboard, you discover the network port no longer works. What is the best and least expensive
    10·1 answer
  • Jenny is working on a laptop computer and has notices that the computer is not running very fast. She looks and realizes that th
    6·2 answers
  • EDVAC stands for? on which theory it is made on?
    15·1 answer
  • The Internet acts as a(n) blank services such as The World Wide Web and email
    6·2 answers
  • How can a search be narrowed to only search a particular website????
    15·1 answer
  • What spreadsheet tool could be used to add together the numbers in a<br> selected group of cells?
    10·1 answer
  • ¿Cuál es la función que cumplía los sofistas y Porque eran tan importantes?​
    13·1 answer
  • Which generation computer supported GUI operating system?​
    11·1 answer
  • How to add links in HTML? ​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!