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
When using powershell, an administrator can use the ____________ cmdlet to create a new dc in a new forest.??
NeX [460]
I am definitely sure that the answer should be: When using powershell, an administrator can use the Install-ADDSForest cmdlet to create a new dc in a new forest. Install-ADDSForest is used to install first domain controller in new forest.  To do that, you should execute this command through the command promt. It looks like this: <span>C:\> Install-AddsForest. Then you'll need to set up the attributes.</span>
8 0
4 years ago
Suppose you will invest $100 per month at the beginning of the month for 40 years with interest rate
Alexeev081 [22]

Answer:

future value = 232369.1361

return % = 384.10 %

Explanation:

given data

principal = $100 per month

time = 40 year = 480 months

rate = 6.25 % yearly = 0.0625 yearly = 0.005208 monthly

to find out

total amount of capital at the end of your investment and percentage is  your total return

solution

so here future value formula is

future value = P \frac{(1+r)^{t-1}}{r} * (1+r)   ..........1

here r is rate and t is time and P is principal

so put all value

future value = 100 \frac{(1+0.005208)^{480-1}}{0.005208} * (1+0.005208)

future value = 232369.1361

so

Total capital at the end of investment-Total principle invested over the years

232369.1361 - 100 ( 12 × 40 )

184369.1361

so

Return % = \frac{184369.1361}{48000} × 100

return % = 384.10 %

5 0
3 years ago
To change the overall design of an entire document to include colors, fonts, and effects, a user should apply a?
lisov135 [29]
Try to use color swatch if not then idk
4 0
3 years ago
Read 2 more answers
Please help in computer subject​
VMariaS [17]

Answer:

6. Read this quote from Ben Hogan below the photograph.

purple

"People have always been telling me what I can't do. I guess I have wanted to show them.

That's been one of my driving forces all my life."

31

What does this quote mean? Use at least two direct quotes from the text that give

examples of this quote.

A

urn

Julie Bahn

3 0
3 years ago
Read 2 more answers
After execution of the code fragment
lesya692 [45]
Yes the output is 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  





8 0
4 years ago
Other questions:
  • The most popular input device of a computer is a(n) ____.
    6·1 answer
  • 4. When determining the tone of their tweets, marketers should consider
    8·1 answer
  • Choose the appropriate of an image that supports the text. You should also make sure that the image is
    12·2 answers
  • 40 POINTS PLZ HELP NEED ASAP!!!
    5·1 answer
  • which of the following is not a windows accessory? a. sticky notes b. windows 8 c. sound recorder or d. paint
    8·2 answers
  • A sequence of data values separated by commas can be made into a list by enclosing the sequence in what type of symbols?
    5·1 answer
  • Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2, the
    7·1 answer
  • The engineering firm you work for is submitting a proposal to create an amphitheater at a state park. Proposals must be submitte
    15·1 answer
  • What made it possible to develop personal computers?
    10·2 answers
  • Which of the following is a good conductor of electricity and heat?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!