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]
4 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]4 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
Describe two ways the ARPANET is different from the internet
spayn [35]
ARPANET was the network that became the basis for the Internet. Based on a concept first published in 1967, ARPANET was developed under the direction of the U.S. Advanced Research Projects Agency (ARPA). In 1969, the idea became a modest reality with the interconnection of four university computers. The initial purpose was to communicate with and share computer resources among mainly scientific users at the connected institutions. ARPANET took advantage of the new idea of sending information in small units called packets that could be routed on different paths and reconstructed at their destination. The development of the TCP/IP protocols in the 1970s made it possible to expand the size of the network, which now had become a network of networks, in an orderly way.
8 0
4 years ago
Um can anyone who is really into science and physics answer this question
Lady_Fox [76]

Answer:

What question?

Explanation:

3 0
4 years ago
A(n) ________ signal is a discrete, binary waveform that transmits data coded into two discrete states such as 1-bits and 0-bits
Dvinal [7]

The signal that is being pertained above that gives a discrete and binary waveform in which data is being transmitted with codes in a states that are two discrete is the digital signal. This signal also has the capability of representing the data in a way that it is sequences based on its discrete values.

5 0
3 years ago
Rate my dog out of ten give explanation why
Karolina [17]

Answer:

10/10

Explanation:

i love dogs. he's a super cute dog and i love him without even knowing him

7 0
3 years ago
Refer to the color wheel to identify the color scheme.
morpeh [17]
C) monochromatic
Hope this helps!

btw make me brainliest?
4 0
3 years ago
Other questions:
  • Why is sequencing important in coding
    8·2 answers
  • Given non-negative integers x and n, x taken to the nth power can be defined as: x to the 0th power is 1 x to the nth power can
    7·1 answer
  • You need to test a condition and then execute one set of statements if the condition is true. If the condition is false, you nee
    9·1 answer
  • Find the maximum value and minimum value in below mention code. Assign the maximum value to maxMiles, and the minimum value to m
    11·1 answer
  • Hey! Would you please help me do this program?
    14·1 answer
  • Explain the differences between apple and android
    14·2 answers
  • Which of the following “invisible” marks represents an inserted tab?
    11·2 answers
  • Sierra needs to ensure that when users are entering data into a datasheet or form that they are limited in the values they can s
    15·2 answers
  • Which of the following screen elements is a horizontal bar that displays at the
    8·1 answer
  • A customer bought a goods for Rs.9,000 after getting 10% discount. Calculate the marked price of the goods.Write in Qbasic.​
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!