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
Romashka [77]
3 years ago
7

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.
Computers and Technology
1 answer:
-BARSIC- [3]3 years ago
6 0

Answer:

#required generator function

def count_seq():

   #starting with number 2. using string instead of integers for easy manipulation

   n='2'

   #looping indefinitely

   while True:

       #yielding the integer value of current n

       yield int(n)

       #initializing an empty string

       next_value=''

       #looping until n is an empty string

       while len(n)>0:

           #extracting first digit (as char)

           first=n[0]

           #consecutive count of this digit

           count=0

           #looping as long as n is non empty and first digit of n is same as first

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

               #incrementing count

               count+=1

               #removing first digit from n

               n=n[1:]

           #now appending count and first digit to next_value

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

       #replacing n with next_value

       n=next_value

#testing, remove if you don't need this

if __name__ == '__main__':

   #creating a generator from count_seq()

   gen=count_seq()

   #looping for 10 times, printing next value

   for i in range(10):

       print(next(gen))

Explanation:

You might be interested in
The _______ displays the data series in separate columns side-by-side so that you can compare the relative heights of the column
k0ka [10]

Answer:

Cluster Column Charts.

Explanation:

Clustered column chart:-It displays multiple data series in separate vertical columns. Each series have the same axis labels.Clustered vertical columns thus allow direct comparison of multiple data series.When having three data series you can compare their heights also.So we conclude the answer is Cluster Column Charts.

3 0
3 years ago
Read 2 more answers
What are some options available when inserting an address block? Check all that apply. previewing postal code full address label
iVinArrow [24]

Answer:

A. previewing

B. postal code

C. full address

E. matching fields

F. company name

7 0
4 years ago
Read 2 more answers
GIVING BRAINLIEST! AND 100 POINTS.
Natalka [10]

Answer:

Communication

Explanation:

Communication is the most common thing to do on your device .

5 0
2 years ago
Read 2 more answers
This performs Arithmetic and Logical Operations *
Zepler [3.9K]

Answer:

The ALU, it's pretty obvious lol!

3 0
2 years ago
May someone help me with the this question pls , The governor of a state wants to inform the people about a change in the tax po
Valentin [98]

Answer:

Option B: News reporters is the correct answer.

Explanation:

First of all we have to observe the reach of all options available in the question. We know that the largest reach in the country or province or state is of media and journalists of that particular region. So the governor should invite the news reporters to convey the message.

Hence,

Option B: News reporters is the correct answer.

5 0
3 years ago
Other questions:
  • What is the value of count after this nested FOR loop executes fully.
    6·1 answer
  • What is the basic unit for storing data in exel
    10·1 answer
  • To support continuous improvement efforts in the workplace, you increase the number of tasks that an employee performs and have
    7·1 answer
  • 2. What is a cap? (0.5 points)
    9·1 answer
  • Shape is very prominent in the image of the telephone other elements are ( Color, Space, or Line) and (Form, Space, or Texture)
    15·2 answers
  • Select the correct answer. Vlad wants to include his goals and target in his résumé. He also wants to add how he can be benefici
    12·1 answer
  • When replacing a thermostat or water pump, coolant drained from the cooling system should be ________.
    9·1 answer
  • What types of information should have their sources cited to avoid plagiarism? List at least 3
    10·1 answer
  • Having sound enhances your App, do you agree with this? Explain.
    9·1 answer
  • Besides your computer, where else can you find and use an operating system?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!