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
yanalaym [24]
3 years ago
5

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.

Your generator function won't just go up to some limit - it will keep going indefinitely. It may need to treat the first one or two values as special cases, which is fine.

Your file must be named: count_seq.py
Computers and Technology
1 answer:
Crank3 years ago
3 0

Answer:

#code (count_seq.py)

def count_seq():

   n='2'

   while True:

       yield int(n)

       next_value=''

       while len(n)>0:

           first=n[0]

           count=0

     

           while len(n)>0 and n[0]==first:

               count+=1

               n=n[1:]

           next_value+='{}{}'.format(count,first)

       n=next_value

if __name__ == '__main__':

   gen=count_seq()

   for i in range(10):

       print(next(gen))

Explanation:

  • Start with number 2. Use string instead of integers for easy manipulation .
  • Loop indefinitely .
  • Yield the integer value of current n .
  • Loop until n is an empty string .
  • Loop as long as n is non empty and first digit of n is same as first .
  • Append count and first digit to next_value .
You might be interested in
Write a program whose input is two integers and whose output is the two integers swapped.
Tpy6a [65]

Answer:

The program to this question can be given as:

Program:

#include <iostream>  //header file

using namespace std;   //using namespace.

void SwapValues(int* userVal1, int* userVal2); //function declaration.

void SwapValues(int* userVal1, int* userVal2) //function definition.

{ //function body.

//perform swapping

   int t = *userVal1;  

   *userVal1 = *userVal2;

   *userVal2 = t;

}

int main() //main method  

{

int n1, n2; //define variable

cout<<"Enter first number :"; //message

cin>>n1; //input by user.

cout<<"Enter second number :"; //message  

cin>>n2; //input by user.

SwapValues(&n1,&n2); //calling function.

cout<<"Swapped values"<<endl;

cout<<"first number is :"<<n1<<endl; //print value

cout<<"second number is:"<<n2<<endl; //print value

return 0;

}

Output:

Enter first number :3

Enter second number :8

Swapped values

first number is :8

second number is :3

Explanation:

The description of the above C++ language program can be given as:

  • In the program, firstly we include the header file. Then we declare and define a function that is "SwapValues()" function in the function we pass two integer variable that is "userVal1 and userVal2" inside a function, we define an integer variable that is "t" and perform swapping.  
  • Then we define the main function in the main function we define two variables that is "n1 and n2" this variable is used to take value-form user. then we pass this value to function and print the function values.

5 0
3 years ago
Which is the best information to determine an athlete's abilities and needed areas of improvement?
katen-ka-za [31]

Answer:

4

Explanation:

7 0
3 years ago
Read 2 more answers
Which of the following is an example of a law that governs the information IT workers may have access to in the course of their
Anit [1.1K]

Answer:

HIPAA

Explanation:

The Health Insurance Portability and Accountability Act of 1996 is a United States federal statute enacted by the 104th United States Congress and signed into law by President Bill Clinton on August 21, 1996.

6 0
3 years ago
In which state of matter is there no particle motion?
kiruha [24]
Solid is your answer for the day
6 0
3 years ago
Select all statements that are true of cable internet connections.
tatyana61 [14]

Answer:

B.) They're broadband connections.

D.) They're shared bandwidth connections.

I hope this helps! ^-^

3 0
2 years ago
Other questions:
  • A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
    9·1 answer
  • Clifford created a table using OpenOffice Writer and entered some information into the table. Later, he needed to add more rows
    15·2 answers
  • What 3 types of technologies are used inside hard drives?
    15·1 answer
  • What careers are most likely to require business skills
    13·1 answer
  • In Microsoft Access, what happens when you save a query once and run it but then add more to the query? What will happen? a)erro
    12·1 answer
  • An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours plus any overtime pay. Ove
    13·1 answer
  • In what type of attack does the attacker send unauthorized commands directly to a database?
    5·1 answer
  • Green Fields Landscaping Company sells evergreen trees which are priced by height. Customers have a choice of purchasing a tree
    15·1 answer
  • In a non-price rationing system, consumers receive goods and services first-come, first served. Give me an example of a time whe
    8·1 answer
  • Point out the wrong statement :
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!