answer.
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
faltersainse
7 days 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:
zubka84 [942]7 days ago
3 0

Response:

#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))

Clarification:

  • Begin with the number 2. Utilize a string for easier manipulation rather than integers.
  • Engage in an infinite loop.
  • Yield the current integer value of n.
  • Continue looping until n becomes an empty string.
  • Repeat as long as n has content and the first digit matches the leading digit.
  • Concatenate the count and the first digit to form next_value.
You might be interested in
Strlen("seven"); what is the output?
oksian1 [797]

Response:

Your answer is A, and I hope this information is useful.

4 0
1 month ago
Create a conditional expression that evaluates to string "negative" if user_val is less than 0, and "non-negative" otherwise.
maria [879]

Answer:

The revised code is as follows:

user_val = int(input())

cond_str = 'non-negative'  

if user_val < 0:

   cond_str = 'negative'  

print(user_val, 'is', cond_str)

Explanation:

This retrieves input for user_val

user_val = int(input())

This sets cond_str to 'non-negative'

cond_str = 'non-negative'

In cases where user_val is below 0

if user_val < 0:

Here cond_str changes to 'negative'

   cond_str = 'negative'  

This displays the intended output

print(user_val, 'is', cond_str)

4 0
1 month ago
What is a commonly publicized password sql injection string?
Rzqust [894]
The phrases "or 1=1" and "or ''=''" are typical examples used to manipulate an SQL WHERE clause into evaluating as true.

Consequently, if you type in <span>' or ''=' as your password, you can authenticate if the query would be:

</span><span>select username,pass from users where username='you' and password='' or ''='<span>' limit 0,1;</span></span>
7 0
9 days ago
The video clip on driverless cars explained that brain signals from the individual wearing the headset are converted by computer
zubka84 [942]

There is a safety concern if the vehicle experiences a malfunction or encounters a red light or police; just operate your own vehicle instead.

5 0
1 month ago
Read 2 more answers
A retailer is able to track which products draw the most attention from its customers through the use of 5g-enabled motion senso
zubka84 [942]

The technology that integrates with 5g capabilities for tracking shopping trends is known as the internet of things.

To clarify, let's define internet of things.

  • The internet of things refers to a network of Internet-enabled objects, often utilizing web services for interaction.
  • There has been a notable development in the Internet where devices maintain network connectivity, allowing them to transmit and receive data.

Based on this explanation, we can affirm that the assertion regarding the technology using 5g capabilities for monitoring shopping behaviors being labeled as internet of things is accurate.

Find out more about internet of things here:

7 0
28 days ago
Other questions:
  • Your computer science teacher asks you to sample a black and white image that is 4" x 6". How would you sample the image to prov
    8·1 answer
  • 3.14 LAB: Input and formatted output: Caffeine levels A half-life is the amount of time it takes for a substance or entity to fa
    9·1 answer
  • To reduce costs and the environmental impact of commuting, your company decides to close a number of offices and to provide supp
    14·1 answer
  • A client is currently struggling with late-stage integration and manual deployments. They want to find another method that will
    5·1 answer
  • Light travels at 3 × 108 meters per second. A light-year is the distance a light beam travels in one year.Write a PYTHON program
    14·1 answer
  • This question involves a simulation of a two-player game. In the game, two simulated players each start out with an equal number
    7·1 answer
  • A client has macular degeneration resulting in moderate visual impairment. The client works as a data entry clerk and wants to c
    15·1 answer
  • RADIAC instruments that operate on the ionization principle are broken down into three main categories based on what?
    15·1 answer
  • What advantage do ExpressCard modules and USB adapters offer over expansion cards?
    5·1 answer
  • What problem does the DNS solve? How does the DNS help the world wide web scale so that billions of users can access billions of
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!