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
Each row in a database is a set of unique information called a(n)
blondinia [14]

A row, which is also called a tuple.

4 0
3 years ago
Read 2 more answers
What's up with this new update?
Andre45 [30]

Answer:

so do i the notifications are out of control i try to ignore them

Explanation:

and yea so it seems you like to do things such as VR? if so i suggest one from the Oculus brand i dont use them but i heard they were good!

~Brianna/edgumacation

4 0
3 years ago
Read 2 more answers
Write an algorithm to calculate the sum of three numbers A, B and C​
kati45 [8]

Answer:

1. Start

2. Display "Enter three numbers"

3. Input A

4. Input B

5. Input C

6. Sum = A + B + C

7. Display Sum

8. Stop

Explanation:

Line 1 and Line 7 of the algorithm implies the start and end of the algorithm, respectively.

Line 2 prompts user for input of three numbers

Line 3 to 5 accept input from user and these inputs are saved in variables A, B and C

Line 6 adds the three inputs and saves the result in variable Sum

Line 7 displays the value of Sum

6 0
4 years ago
The idea that the number of transistors on integrated circuits doubles approximately every two years is known as Moore's Law.
igor_vitrenko [27]
False<-------------------
7 0
4 years ago
A crowd-funding open source business model, called _______, is where users offer money as a reward for new software or new featu
Lana71 [14]

Answer:

bounties        

Explanation:

The bounties are a free or open-source business model for the funding.It is is a payout or bonus which an offered by the community as a bonus or incentive or reward The bounties is offered when someone task to be done by not normally associated with the member or group.

In the software point of you, the bounties are defined as when the user gives a reward in the existing software when some new features are added into that software.  

5 0
3 years ago
Other questions:
  • In the 2000s, Venezuelan President Hugo Chàvez instituted economic policies that caused smuggling and hoarding of food. What did
    15·1 answer
  • Read the sentence from the first paragraph of Silent
    6·2 answers
  • Crop marks are used on an illustration to indicate to the printer the
    10·1 answer
  • How many questions do you need to have on brainly before being able to send messages?
    14·1 answer
  • Write an abstract data type for a queue in Java whose elements are generic elements of type T that have an associated integer pr
    15·2 answers
  • What is a text based language that can be used to build all kinds of things ????
    9·1 answer
  • Puter Science (IS)
    14·1 answer
  • What is a network computer that processes requests from a client server​
    11·1 answer
  • Can anyone help with this?​
    6·1 answer
  • Need help coding this it uses input and I need to use the words good and morning
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!