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
Which of the following statements about the use of desktop publishing software is true
VLD [36.1K]
What did you do when you got to school tomorrow and then again I don't want it
4 0
2 years ago
ZeroIt is a function that takes one argument and returns no value. The argument is a pointer to int. The function stores the val
Sedbober [7]

Answer:

zeroIt(&x);

Explanation:

The statement that sets the value stored in x to zero by invoking the function zerolt is given below

zeroIt(&x);

The zeroIt function is also given below for better understanding.

void zeroIt(int *x) {

   *x = 0;

}

As seen, the function takes an argument with integer variable type, which is a pointer, denoted by the asterisk symbol (*x).

The ampersan sign (&x) is used to access the variable whose value can then be stored.

7 0
3 years ago
Matthew is working to select an authentication method for his company that will support REST as well as many web-based and mobil
vitfil [10]

Answer:

C) OpenID Connect

Explanation:

The best option is OpenID Connect because is based in OAuth, and supports multiple web based and mobile clients, and supports REST.

With OAuth, we cannot make any user authentication just provide a token to access data.

RADIUS is a networking protocol, and Shibboleth is a single sign-on log-in system for computer networks and the Internet, both not support REST.

6 0
2 years ago
How fast will a viral meme spread if it is not contained within 24 hours?
sveta [45]
Well a viral meme would spread very fast, it's a VIRAL meme which means it would spread faster than a normal meme. Even if it is contained in the 24 hour time period it would still become rather popular.
6 0
3 years ago
Read 2 more answers
Consider the following code: <br> x=9 y = -2 z=2<br> print (x + y * z)<br> What is output?
Goryan [66]

Answer:

14

Explanation: The reason why is because adding a negative is pretty much subtracting by 2. 9-2=7. Then multiply 7 by 2 like add 7 to 7 and you get 14.

3 0
3 years ago
Other questions:
  • The code selection above is taken from the Color Sleuth activity you just completed. This selection would count as an abstractio
    12·1 answer
  • Write a program that reads in 10 numbers from the user and stores them in a 1D array of size 10. Then, write BubbleSort to sort
    13·1 answer
  • Operating system software allows you to use your fingers, a mouse or other pointing device to select screen controls, such as bu
    5·2 answers
  • "Different links can transmit data at different rates, with the _______ of a link measured in bits/second"
    11·1 answer
  • From an IT perspective, which of the following best describes BI and BI apps?
    13·1 answer
  • Write a loop that inputs words until the user enters STOP. After each input, the program should number each entry and print in t
    12·1 answer
  • You insert a comment in a worksheet by using a command on the ____ tab on the Ribbon.
    13·1 answer
  • In the context of computer and network security, _____ means that a system must not allow the disclosing of information by anyon
    10·1 answer
  • What are village by laws​
    12·1 answer
  • To use the replace feature we can simply just press Carl+h,Carl+c,Carl+r
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!