Question
Coding with python and I'm in the introductory course so make sure the module and function is not too complex involving things that we haven't
Coding with python and I'm in the introductory course so make sure the module and function is not too complex involving things that we haven't learned.Thank u!
Certain machine parts are assigned serial numbers. Valid serial numbers are of the form: SN/nnnn-nnn where n represents a digit. Write a function valid_sn that takes a string called serial_num as a parameter and returns True if the serial number is valid and False otherwise. For example, the input
"SN/5467-231" returns True
"SN5467-231" returns False
"SN/5467-2231" returns False Using this function, write and test another function valid-sn-file that takes three file handles as input parameters. The first parameter called handle_in is the file containing a list of serial numbers, the second and third parameters called handle_valid and handle_invalid respectively, are to output files. Write all valid serial numbers to the second file handle and invalid serial numbers to the third. Save the functions in a PyDev library module named a9_functions.py Write a program q4.py that tests valid-sn-file function and write/print the results to the output files: output_q4_valid.txt and output_q4_invalid.txt Test your program with the sample file provided serial_number.txt.
serial_number.txt =
SN/5467-231 SN5467-231 SN/5467-2231 SN/1234-978 SN/1607-123 SN/1408-456 SN5467-231 SN123-1234 SN*12345672 SN/2304-567
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started