Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON ONLY! Write a program longest_stretch.py that writes the longest contiguous sequence of equal integer values, from the sequence of integers read from the command

image text in transcribedPYTHON ONLY!

Write a program longest_stretch.py that writes the longest contiguous sequence of equal integer values, from the sequence of integers read from the command line. If there are multiple stretches of the same length, the program should write the first one. $ python longest_stretch.py 1 1 2 3 4 4 4 5 5 6 6 6 7 4 4 4 $ python longest_stretch.py 1 1 2 3 4 4 4 5 5 6 6 6 6 6 6 6 6 $ python longest_stretch.py 1 1 2 3 4 4 4 5 5 6 6 6 6 7 6 6 6 6 $ python longest_stretch.py 1 2 3 4 5 1 # command line. import stdio import sys # Create a list a consisting of the integers from the command line. a = for V in # Identify the starting position ms and length ml of the longest contiguous # sequence of integers (ie, the longest stretch) from a. s = 0 # current stretch start 1 = 1 # current stretch length ms = 0 # longest stretch start ml = 0 # longest stretch length for i in range(1, len(a)): # If a[i] is different from a[i - 1], then we have the start of a new # stretch. In that case, if 1 is greater than m1, set ms to s and ml to 1, # and set s to i and 1 to 1. Otherwise, increment 1 by 1. # Again, if 1 is greater than ml, set ms to s and ml to 1. # Write the longest stretch from a, separating each by a space, and with a # newline at the end. for i in range (, )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

4. How could you face and handle a similar challenge in the future?

Answered: 1 week ago