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
There is a natural tendency on the part of users and system managers to perceive little benefit from security investment until a
spayn [35]

Answer:

The answer is True

Explanation:

Users and system managers/administrators do not necessarily see the use of security investments, because there is no security breach or security failure to the system.

When security infrastructures are in place, it is to prevent or at least reduce the possibility of devaluation, modification, corruption, destruction or deletion, disruption, disclosure, use, and inappropriate or unauthorized access. So, if any of these breaches do not occur, system managers and users perceive little benefits from security investments.

6 0
3 years ago
Explain the danger leaks pose when operating a tractor.
Romashka [77]
Read and follow procedures as outlined in the operator's manual. By being familiar with the operating features of a tractor, the operator will develop confidence when the tractor is driven under adverse conditions. Learn the location and purpose of all of the guages and controls as well as other indicators. Knowing where the controls are by memory can allow you to react more quickly in an emergency situation. There have been accident situations where individuals have become entangled in machinery or the power takeoff shaft and rescuers or family did not know how to disengage the equipment. Family members should be showed how to shut down equipment or disengage the PTO in case of emergency.
Study the various decals on your equipment. They may point out DANGER, WARNING and CAUTION for various points on the tractor. Have an experienced tractor operator with you as you review the various decals and ask questions!
5 0
3 years ago
What web revolution enables user to generate content​
ch4aika [34]

Answer:

<u>web 2.0 internet</u>

<u>Explanation:</u>

<u>Explanation:</u>

Tim O Reilly in 2004 changed the web with his web 2.0 concept which according to him at the time would allow enable the user to generate content.​

4 0
4 years ago
_________ was demilitarized by Germany because of the Treaty of Versailles. The Rhineland The North Sea The Ruhr Valley Eastern
Alchen [17]

The Rhineland was turned into a demilitarized zone because of the Versailles Treaty.   -From 1919, Germany wanted to get rid of this zone because it left them open to attack from Belgium, Holland and France.   In March 1936, Germany's army occupied the Rhineland.

8 0
3 years ago
Read 2 more answers
George wants to edit the font of the title text in his presentation. Where can he find the option to edit it?
liberstina [14]
The answer is the answer choice D
4 0
4 years ago
Read 2 more answers
Other questions:
  • Directions: pick the right letter for each number.
    11·2 answers
  • 12. Which of the following is a complex formula?
    13·2 answers
  • Personality traits such as thoughtfulness, empathy, self-control, and goal orientation belong to the _____ category.
    5·2 answers
  • Which item is used in Excel to identify the row of a particular cell? letter number type sheet
    6·2 answers
  • Methods can be ____ correctly by providing different parameter lists for methods with the same name.
    7·1 answer
  • What internet access technology currently uses a technology called 4G?
    13·1 answer
  • What is Geocortex and how does it work in web or mobile?
    11·1 answer
  • True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type,
    8·1 answer
  • Write the definition of a function named isSorted that receives three arguments: an array of int , an int that indicates the num
    11·1 answer
  • Rewrite the following program segment using a while loop instead of a for loop.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!