Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Unexpected changes to data need to be guarded against, and data can be accompanied by a checksum to help detect errors. A checksum is a

Unexpected changes to data need to be guarded against, and data can be accompanied by a checksum to help detect errors. A checksum is a computation that is performed over all the data it protects, and the computed value is stored with the data. Upon reading or transmitting the data, the data checksum is recomputed and compared to the stored value; if they differ, then this tells you that the data has changed.
In this section you will be writing a program to recompute and verify a simple checksum for data files. The data files consist of lines of text followed by the sentinel END on a line by itself. The line following the END has a checksum value for the data, which is an integer value greater than or equal to zero.
The checksum is the sum of the lengths of the lines comprising the data. The END sentinel and the checksum itself are not added to the checksum. For example, here is one possible data file:
foo
garble
blarg
END
14
The checksum is 14 because the length of "foo" plus the length of "garble" plus the length of "blarg" equals 14. If the checksum were a value other than 14, then your program would indicate a checksum error.
Start with the following code:
SENTINEL = 'END'
chksum = AAA
while BBB:
line = input()
if CCC: DDD
chksum = EEE oldchksum = FFF
if GGG:
print('checksum error')
The code is run by typing
spy3 section3.py < datafile
1) What should AAA be replaced with?
0, 1 ,'14' ,14
2) What should BBB be replaced with?
input() != SENTINEL , input() != 'END' , True ,0 , False.
3) What should CCC be replaced with?
line == 'SENTINEL' , line = 'END' ,line == 'END'
, line = SENTINEL , line == SENTINEL
4) What should DDD be replaced with?
continue , Nothing , break , line = input()
5) What should EEE be replaced with?
chksum len(line)
chksum + int(line)
chksum + len(line)
chksum + line
chksum int(line)
6) What should FFF be replaced with?
int(input())
int(input)
input()
line
int(line)
7) What should GGG be replaced with?
chksum = oldchksum
chksum or oldchksum
chksum != oldchksum
chksum == oldchksum

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

=+ b. How would the change you describe in part

Answered: 1 week ago