Write a function,AnalyseStudents(), which receives anumberand determines whether the number is avalid student number or not. Use the following validity test to determine thevalidityof a student...


Write a function,AnalyseStudents(), which receives anumberand determines whether the number is avalid student number or not. Use the following validity test to determine thevalidityof a student number:


Student number: 20570856
sum=(2*8)+(0*7)+(5*6)+(7*5)+(0*4)+(8*3)+(5*2)+(6*1)
result=sum%11


If theresult equals 0, the number is avalid student number; if the result isnot equal to 0, the number is aninvalid student number. The functionMUSTuse a loop to analyse the number by looking at each individual digit in the number.
In addition, the number mayonly be 8 digits longand mayonly contain numeric values.


The function returns a1 (valid)or0 (invalid)to the calling statement.


Implement error handling (try-except) to intercept and handle any runtime errors to prevent the program from crashing. Any such errors must return a0 (invalid)to the calling statement.


Part 2


The attached file,Data.txt, contains a list of valid and invalid student numbers. Write a function,Read(), which receives anempty listas argument. The function must thenread the student numbers from the file and save it in the list. Thenumber of linesread from the Data.txt file must bereturnedto the calling statement.


Implement error-handling (try-except) to intercept and handle any runtime errors while reading the file to prevent the program from crashing. If thefile can not be read, anappropriate messagemust be displayed and the program mustterminate("exit").


Part 3


Write a function,Write(), which receives astudent numberandstatusof the student number as arguments. If the student number isvalid, i.e. status = 1, the number must be written to an output file,ValidNumbers.txt. If the student number isinvalid, the number must be written to an output file,InvalidNumbers.txt. The number and status aredisplayed on the screen in both cases.


Part 4


Write a Python program that implements thethree functions in Parts 1-3:



  • Send an empty list to Read() and display the number of lines that have been read.

  • For each student number in the list


    • Determine whether the number is valid or not with AnalyseStudents().


    • Send the student number and its status to Write().



Jun 03, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here