It helps you keep things organized and easier to find files
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.
Answer:
Following are the method to this question:
def __init__(self, _name, _breed):#defining Constructor
""" Constructor """
self.name = _name#assigning value in name variable
self.breed = _breed#assigning value in breed variable
self.tricks = []#defining tricks an empty list
Explanation:
In the above code, a parameterized constructor is defined, that hold two-variable "name and breed" in its parameter, and another object self is created for storing the value.
Inside the constructor two-variable, and one empty list variable "tricks" is defined that hold value in the name and breed variable, and the next step an empty list is defined, that store its value.
Answer:
The answer to this question is "Option a".
Explanation:
The description of the JavaScript code as follows:
- In the code, there is two variable defined that are "years and months". The years convert string value in number and calculate years and holds value in years variable and months variable calculate the moths and holds value in months variable.
- Then we use conditional statements in this statement we use two if blocks. In first if block we check that years variable value is equal to 0. if this condition is true. it will print months in the alert box.
- In second if block we check that if months variable value is equal to 0. if this condition is true. it will print years in the alert box.
- In else block, we use an alert box that prints years and months.