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
? Create a home page that introduces the rental car company. the page should have a header and footer. in the document body, it
Anestetic [448]
You need some more criteria. Is this a webpage? If so.. What language(s) are applicable for writing your web application. My profession is systems development, do I do a lot of fronte-end/ back-end development. I don't mind helping, just need some more information. If not what resource does this need to be created in?
7 0
3 years ago
Differences of a desktop computer and a laptop
Ilya [14]

Answer:

Desktop can't move easily, not portable. Laptop very portable.

Explanation:

6 0
2 years ago
you have been tasked with configuring a digital information station in the office's lobby. guests will be able to use the statio
REY [17]

The most important security consideration for the station is code signing. With code signing, consumers may feel confident about the software they are downloading and can stop worrying about infecting their computer.

With code signing, consumers may feel confident about the software they are downloading and can stop worrying about infecting their computer or mobile device with malware. Code signing has grown in importance for software developers and distributors as more software may be downloaded from the Internet.

Malware can be easily installed on a victim's computer by an attacker who poses as a trustworthy source. As long as users only download software that is regarded as safe by their operating system, code signing ensures that these types of assaults cannot happen.

Nowadays, the Operating System looks for the digital certificate produced through code signing when software is downloaded onto a computer to ensure the security of the software being installed. The user is informed and given the option to stop or continue the installation if no digital certificate is detected.

To know more about code signing click here:

brainly.com/question/28860592

#SPJ4

3 0
10 months ago
1.
aliya0001 [1]
#1 is D #2 is B #3 is A #4 is D #5 is B
3 0
3 years ago
Read 2 more answers
HTML importance in web desgin<br>​
Inessa [10]

Answer:

HTML is a significant tool for building up a site. It is a programming language used to describe the structure of information on a web page.

Explanation:

6 0
3 years ago
Other questions:
  • Below is a chart representing portions of resumes from 3 applicants. Which best explains the applicants careers?
    11·1 answer
  • Class CTRivers describes collection of CT rivers. It has no data, and it provides the following service methods. None of the met
    13·1 answer
  • Consider the clipping of a line segment in two dimensions against a rectangular clipping window. Show that you require only the
    10·1 answer
  • Egyptian hieroglyphs were part of a writing system used by the ancient Egyptians. What type of graphic design elements did they
    13·1 answer
  • Which statement correctly compares blank presentations and themed presentations?
    12·2 answers
  • Write a Python 3 script in PyCharm that will simulate the game of "Rock, Paper, Scissors": Display a header and the simple rules
    8·1 answer
  • Which statement describing the arcade games played in the 1970s is true?
    14·1 answer
  • Which of the following expressions in Java is equal to 4?
    11·1 answer
  • Explain any two types of board band connection​
    11·1 answer
  • To make the monster pace, you needed the monster to turn ___ degrees.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!