Question

In: Computer Science

def hiCount(iterable): rtnVal = 0 most = '' for item in iterable: num = iterable.count(item) if...

def hiCount(iterable): rtnVal = 0 most = '' for item in iterable: num = iterable.count(item) if num > rtnVal: most = item rtnVal = num return tuple(most, rtnVal) lyric = "you don't own me" print(hiCount(lyric))

does all the for then the return

Python

Solutions

Expert Solution

Here is the correct answer...

CODE:

def hiCount(iterable):
'''program to print chracter which occur max times '''
rtnVal = 0
most = ''
for item in iterable: #traverse through string iterable
num = iterable.count(item) #count occurence of charcter
#print(num)
if num > rtnVal: #find max count
most = item #mark down the character
rtnVal = num #store max count
#return tuple([most,rtnVal]) #correct usage of tuple function
#it takes one argument as parameter
return (most, rtnVal) #here it returns tuple of most and rtnval
  
lyric = "you don't own me"
#print(hiCount.__doc__)
print(hiCount(lyric))

CODE Snapshot:

OUTPUT:

If you have any doubts please COMMENT...

If you understand the answer please give THUMBS UP...


Related Solutions

Exercise: Write a program named factorial.py that contains the following two functions: def while_factorial(num) def for_factorial(num)...
Exercise: Write a program named factorial.py that contains the following two functions: def while_factorial(num) def for_factorial(num) These should calculate the factorial of a given number represented by the argument num using a while loop and a for loop respectively.
def num_to_digit_rec(num, base): """ Return a list of digits for num with given base; Return an...
def num_to_digit_rec(num, base): """ Return a list of digits for num with given base; Return an empty list [] if base < 2 or num <= 0 """ # Write your code here return [] def digit_sum(num, base): """ Return the sum of all digits for a num with given base Your implementation should use num_to_digit_rec() function """ # Write your code here return 0 def digit_str(num, base): """ Given a number and a base, for base between [2, 36]...
def vend():     a = {'key':'0','item': 'chips', 'price': 1.50, 'stock': 6}     b = {'key':'1','item': 'cereal',...
def vend():     a = {'key':'0','item': 'chips', 'price': 1.50, 'stock': 6}     b = {'key':'1','item': 'cereal', 'price': 1.25, 'stock': 10}     c = {'key':'2','item': 'pop', 'price': 1.75, 'stock': 12}     d = {'key':'3','item': 'apple', 'price': 2.50, 'stock': 6}     e = {'key':'4','item': 'orange', 'price': 1.95, 'stock': 10}     items = [a, b, c, d, e]     credit = 0 # cash in machine # show items, prices def show(items):     while True:             s = input("> ")             if s...
Python ONLY ONE STATEMENT ALLOWED PER FUNCTION (ONE RETURN STATEMENT ALLOWED) def plsfollowrule(num): return num like...
Python ONLY ONE STATEMENT ALLOWED PER FUNCTION (ONE RETURN STATEMENT ALLOWED) def plsfollowrule(num): return num like this. 1) create a function popular. The dictionary called database contains each people's hobby and their excitement level. This function searches the dictionary and returns a list of that most popular hobby to least popular hobby. If multiple hobbies have the same number of popularity, follow alphabetical order. #What is popular means? The dictionary contains each people's hobby. The programmer should search the dictionary...
def vend():     a = {'key': '0', 'item': 'choc', 'price': 1.50, 'stock': (2)}     b = {'key': '1',...
def vend():     a = {'key': '0', 'item': 'choc', 'price': 1.50, 'stock': (2)}     b = {'key': '1', 'item': 'pop', 'price': 1.75, 'stock': 1}     c = {'key': '2', 'item': 'chips', 'price': 2.00, 'stock': 3}     d = {'key': '3', 'item': 'gum', 'price': 0.50, 'stock': 1}     e = {'key': '4', 'item': 'mints', 'price': 0.75, 'stock': 3}     items = [a, b, c, d, e]          def show(items):         cim = 0         for item in items:             if item.get('stock') == 0:                 items.remove(item)         for item in items:             print(item.get('key'), item.get('item'),item.get('price'),...
What will the following code segments print on the screen? int num = 3; switch (num){...
What will the following code segments print on the screen? int num = 3; switch (num){             case 1:                         System.out.println(“Spring”); case 2:                         System.out.println(“Summer”); case 3:                         System.out.println(“Autumn”); case 4:                         System.out.println(“Winter”); }
public List<Item> findItems(Lookup query) { ArrayList<Item> matches = new ArrayList<Item>(); for (int i = 0 ;...
public List<Item> findItems(Lookup query) { ArrayList<Item> matches = new ArrayList<Item>(); for (int i = 0 ; i < numItems ; i++ ) { Item item = items[i]; if (query.matches(item)) { matches.add(item); } } return matches; } "To improve readability, each line of code should be indented under its parent (i.e. methods should be indented under the class, code in methods should be indented under the method, code in if statements should be indented under the if, etc.). This if rcurly...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10;...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10; i++){ cout << " Enter " << i << " number: "; cin >> num; if ( num%2==0){ even++; sum+=num; } else { odd++; sum2+=num; if(num>largest){ largest = num; } if(num<largest) { smallest = num; } } cout << " The sum of even number is : " << sum << endl; cout << " The total-count of even number is : " <<...
def main():     # keeping asking user for a word or name until user enters 0    ...
def main():     # keeping asking user for a word or name until user enters 0     while True:         word = input('Enter a word/name to convert (enter 0 to quit): ').upper()       if word == '0': break         print(convert_to_soundex(word)) Whenever i try to run the program it tells me unintend doesn't match any outer identation level !!!!
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2:...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2: return 2 if n == 3: return 6 if n == 4: return 4 * annoying_factorial(3) if n == 5: return 5 * annoying_factorial(4) if n == 6: return 6 * annoying_factorial(5) else: return n * annoying_factorial(n-1) def annoying_fibonacci(n): if n==0: return 0 if n==1: return 1 if n==2: return 1 if n==3: return 2 if n==4: return annoying_fibonacci(4-1)+annoying_fibonacci(4-2) if n==5: return annoying_fibonacci(5-1)+annoying_fibonacci(5-2) if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT