Question

Create a function called, convert. This function receives a string parameter called word which only contains...

  • Create a function called, convert. This function receives a string parameter called word which only contains digits (the string represents a positive number) and returns a list of numbers. This is how the function works:

  • - This function calculates the number of times each digit has repeated in the input string and then generates a number based on that using the following formula and adds it to a list. For instance, if the digit x has been repeated n times, then the function will calculate n*10+x and adds it to the list.

  • Example input: “6743672316” In the above string:

    • - 6 is repeated 3 times. Then the corresponding number to be added to the list is 3*10+6 = 36

    • - 7 is repeated 2 times: The number to be added to the list 2*10+7 = 27

    • write a python program

    • - 4 is repeated once: The number to be added to the list is 1*10+4 = 14

    • - 3 is repeated 2 times: The number to be added to the list is 2*10+3 = 23

  • - 2 is repeated once: The number to be added to the list is 1*10+2 = 12

  • - 1 is repeated once: The number to be added to the list is 1*10+1 = 11

  •     

Homework Answers

Answer #1

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:

def convert(word):
list2=[] #empty list
list1=[int(d) for d in word] # take each digit into list1.
  
list1.sort(); #sort the list1.


i=0
  
while i<len(list1): #condition i < length of list1.
  
item=list1[i]
count=1
for j in range(i+1,len(list1)): # for loop used to same elements.

if(item==list1[j]): #condition same elements.
count =count+1
result=count*10+item #calculate result.

list2.append(result) #add to the list2/
i = i+count


return list2

  
list2=[]
word=input("Enter word: ") #scan input.
list2=convert(word) #calling function.

print(list2) #print result.

OUTPUT:

SCREENSHOT OF THE CODE:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python function which receives 3 lists as its input parameters and combines the lists...
Write a Python function which receives 3 lists as its input parameters and combines the lists and remove repeated numbers from the combined list and return the combined list. For instance, if the input is [1,2,3,4,2,3] and [3,4,6,7] and [-1,0,23,4] the result is [1,2,3,4,6,7,-1,0,23] - Note, the order the lists are combined together does not matter. Use main function.
Python. create a function that takes a string as a parameter and prints out the following...
Python. create a function that takes a string as a parameter and prints out the following details as the example output below. If the string is "Hello, my name is Starling, Clarice. My, my, my, nice to meet you." The output would be: Unique words: 10 Number of commas: 5 Number of periods: 2 Number of sentences: 2 (HINT: Use the following string methods: split, lower, count, replace, format, and use the following functions: set, len. You may need to...
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
python pls Create function math_life() this function takes one or more argument. If this function called...
python pls Create function math_life() this function takes one or more argument. If this function called with no argument, raise typeError. The math_life() function returns to a function defined inside. this will take a one argument. For the second argument, it will calculate second function passed to math_life(). You should assume that the math_life() passed x functions, when it called the x times it will calculate the xth function passed to math_life() arguments when it called x+1 time it again...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as an input. The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say xx, come together. Let the frequency of a character, lying in...
This question is broken into 3 parts, each of which builds on the functions developed in...
This question is broken into 3 parts, each of which builds on the functions developed in the previous part. Note that you can (and should) still answer parts (b) and (c) even if you cannot answer the preceding parts - just assume that the functions work as they should, and continue. Please explain the code as well Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The...
A keypad code consists of a string of symbols of length 6 from set {1, 2,...
A keypad code consists of a string of symbols of length 6 from set {1, 2, 3, 4, 5, 6, 7, 8, 9}. Note that the digit 0 is not allowed. A) how many keypad codes of length 6 have at least one repeated symbol? B) how many such keypad codes use the symbol 6 at least once and use the symbol 7 at least once?
Using C programming Create a function called printMenu( ) with the following properties: Has no function...
Using C programming Create a function called printMenu( ) with the following properties: Has no function inputs or output. Prints the following menu to the screen: 1. Enter user name. 2. Enter scores. 3. Display average score. 4. Display summary. 5. Quit Create a function called printLine( ) with the following properties: Takes as input a char Takes as input an integer corresponding to the number of times to print the character Has no function output. For example, if we...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • MS KP MM Corporation is a manufacturer that produces cosmetics. The following information has been taken...
    asked 7 minutes ago
  • Dr. Bunson Honeydew and Dr. Strangepork both wanted to know how effective TV ads were at...
    asked 8 minutes ago
  • 1)  Consider the following temperature surroundings. Ground level, 21oC; 500m, 20oC; 600m, 19oC; 1000m, 20oC. If we...
    asked 14 minutes ago
  • 1. An AA iron-nickel battery delivers a constant current of 750 mA at 1.2 V (a)Calculate...
    asked 18 minutes ago
  • In the process of recrystallization, after dissolving the product in hot methanol, why do we have...
    asked 32 minutes ago
  • Finish buildFloat(): It does three things: Given exponent it computes exponentPattern. If exponent is less than...
    asked 32 minutes ago
  • A chemist has two large containers of sulfuric acid solution, with different concentrations of acid in...
    asked 42 minutes ago
  • Training Goal: Based on Enterprise business strategy and goals develop several training goals based on your...
    asked 42 minutes ago
  • Let f(x) = 5x2 + x − 2. Use the limit definition of f′(a) and the...
    asked 42 minutes ago
  • "Discuss whether free market is necessarily efficient. Give some examples to illustrate the limitations of government...
    asked 1 hour ago
  • Three separate random samples of students (one sample selected from each of three different colleges) were...
    asked 1 hour ago
  • , NEED ANSWER ASAP / ANSWER NEVER USED BEFORE, COMPLETELY NEW ANSWER PLEASE Discuss an example...
    asked 1 hour ago