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
yanalaym [24]
3 years ago
5

Write a generator function named count_seq that doesn't take any parameters and generates a sequence that starts like this: 2, 1

2, 1112, 3112, 132112, 1113122112, 311311222112, 13211321322112, ...
To get a number in the sequence, enumerate how many there are of each digit (in a row) in the previous number. For example, the first number is "one 2", which gives us the second number "12". That number is "one 1" followed by "one 2", which gives us the third number "1112". That number is "three 1" followed by "one 2", or 3112. Etc.

Your generator function won't just go up to some limit - it will keep going indefinitely. It may need to treat the first one or two values as special cases, which is fine.

Your file must be named: count_seq.py
Computers and Technology
1 answer:
Crank3 years ago
3 0

Answer:

#code (count_seq.py)

def count_seq():

   n='2'

   while True:

       yield int(n)

       next_value=''

       while len(n)>0:

           first=n[0]

           count=0

     

           while len(n)>0 and n[0]==first:

               count+=1

               n=n[1:]

           next_value+='{}{}'.format(count,first)

       n=next_value

if __name__ == '__main__':

   gen=count_seq()

   for i in range(10):

       print(next(gen))

Explanation:

  • Start with number 2. Use string instead of integers for easy manipulation .
  • Loop indefinitely .
  • Yield the integer value of current n .
  • Loop until n is an empty string .
  • Loop as long as n is non empty and first digit of n is same as first .
  • Append count and first digit to next_value .
You might be interested in
If E=mc2 then what does F equal?
Vladimir79 [104]

Answer:

First of all,there is not theory F=ma^2!!

Its F=ma and they are definitely not the same.Here F means force and E means Energy.

a means acceleration, but c means the velocity of light. Clearly there's difference between acceleration and velocity and force and energy.

F=ma can be applied on things we normally see but E=mc^2 is applied on things that can travel nearly in light speed!which means atoms,molecules, protons,electrons etc. energy can be determined by the Einstein theory but F=ma is for determining human energy, or energy of cars,vehicles or any regular moving things

Explanation:

4 0
3 years ago
X = 0
cricket20 [7]

The missing line would be x+= num

This means that every time a number is selected from the range it is added to the value of x.

3 0
3 years ago
Who watches the show gravity falls, if you do, if you play the theme song for the first episode backwards you get a hiding messi
Yakvenalex [24]
I don’t really knowwww but thanks
4 0
3 years ago
Read 2 more answers
The most popular input device of a computer is a(n) ____.
zaharov [31]
A keyboard and a mouse

7 0
3 years ago
What’s the purpose of balancing or monitoring your checking account?
emmasim [6.3K]
B) To help you calculate how much money you have in your account.
3 0
3 years ago
Read 2 more answers
Other questions:
  • This type of connection uses radio waves to connect devices on a network.
    9·2 answers
  • Survey Q. Non-scoring: What role is played in the team? (1 correct answer)
    14·1 answer
  • Name some of the file extensions for images and provide more information about one or two of them.
    12·1 answer
  • What is the maximum number of fonts that should be used on a slide?
    13·1 answer
  • Which type of hypervisor does not run on an underlying operating system?
    13·1 answer
  • Which type of malware can hijack internal windows components and often goes undetected because it is already loaded when the ant
    14·1 answer
  • Suppose the price of a complement to LCD televisions falls. What effect will this have on the market equilibrium for LCD​ TVs? T
    13·1 answer
  • Write a function so that the main program below can be replaced by the simpler code that calls function mph_and_minutes_to_miles
    7·1 answer
  • Cloud computing allows organizations to rent computing resources from providers instead of having their own locally managed ____
    7·1 answer
  • If Anyone can help me out that'll be great
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!