Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In language \"python\" create a program that: Write a validation tool to read in

ID: 3594307 • Letter: I

Question

In language "python" create a program that:

Write a validation tool to read in the file called data.txt. Besides the obvious rules like a character_value can only hold one character, only N C D are allowed as field type values. Rules:

The numeric field contains an actual numeric value: A possible negative sign, followed by either an integer or a floating-point number (which will always have an integer portion)

The date field contains a valid date, in mm/dd/yyyy format. (For the purposes of this assignment, you need only ensure that date is the proper format, that the month is between 1 and 12, and that the date is between 1 and 31) ....If the data.txt file is not correct for each requirment state NO , if it is fine state OK.

Example Format:

record number | size | username | transaction | field type | numeric_value | character_value | date_value |

Explanation / Answer

Hi,

I've understood your requirement clearly and implemented the code as per your requirement and tested. You can run the following code directly. Please take care tab spaces as answer box is not allowing to paste the code as it is.

Code:

fname = raw_input("Enter file name: ")

with open(fname) as f:

content = f.readlines()

for i in range(len(content)):

print i

arr = content[i].split("|")

if(arr[4]!="N"):

if(arr[4]!="C"):

if(arr[4]!="D"):

print "NO"

break

if(len(arr[6])!=1):

print "NO"

break

if not(arr[5].isdigit()):

try:

float(str)

except :

print "22NO"

break

date = arr[7].split("/")

mm = int(date[0])

dd = int(date[1])

yy = int(date[2])

if(mm<1 or mm>12):

print "NO"

if(dd<1 or dd>31):

print "NO"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote