Question: Write a Python 2.7.2 script that does the following: Opens the disk file sequence.txt; the format of this file is one integer value per line.

Write a Python 2.7.2 script that does the following:

Opens the disk file "sequence.txt"; the format of this file is one integer value per line.

Determines if there exists anywhere in the file an "acceptable" sequence using a=3 and epsilon=7.

If an acceptable sequence is found, print Accept X to the Python console, where X is the length of the sequence found.

If an acceptable sequence is not found, print BOGUS to the Python console.

Here is a general outline of steps to take:

Open "sequence.txt" Read numbers from the opened file until 3 (the a in this assignment) is found OR there is no more data in the file. If a 3 was found, then the current sequence length (so far) is 1 Read text lines until the file is depleted of data Convert each text line to a value For each value, increment the current sequence length if an epsilon value (7) is read, then read past the next number, it doesn't matter what value it is. Be sure to increment the sequence length appropriately. if the value 3 is read (an a!) then break out of this reading loop, you've found the end of the sequence! Depending on the sequence length and the last value read from the file, you can report the length of an acceptable sequence, or BOGUS. For testing purposes, create a text file with the following values (one per line): 3 10 20 30 40 3 The preceding sequence should work, and the following one should not: 1 3 4 5 6 7 8 9 8 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!