+1 (315) 557-6473 

Python Program to Determine Whether a Code Is Valid Basic Positional or UPC Code Assignment Solution.


Instructions

Objective
Write a program to determine whether a code is valid Basic Positional or UPC code in python.

Requirements and Specifications

Write a program to complete your Python assignment that will repeatedly ask the user for a code (integer) and determine whether it’s a valid Basic, Positional or UPC code. Some integers may be valid for more than one of the codes.
Program is to consist of 2 files:
Assign2.py which handles all the input & output.
code_check.py
Assign2.py handles all the input & output and should repeatedly prompt the user for input, a strong of digits, and then call functions in code_check.py to determine whether the digits in the string correspond to one of the above codes (Basic, Position, UPC).The program should have a list for each type of code and when it finds that the string is a certain type of code, it should add the string to the list for that type of code. If a string is not one of the 3 types of codes, it should add it to a separate list. The user should be repeatedly prompted for a string until they enter a string that is zero (‘0’). Each list should be output when the user has finished.
code_check.py is to consist of 3 functions, one for each type of code. Each function should take a string as a parameter, e.g. ‘24528334’ or ‘033367258’, and determine whether it is a valid code. The function should return ‘True’ or ‘False’.
The program will use expressions, decisions, input/output, loops, lists and functions in Python. The output is to begin with the keyword ‘Summary’, followed by each type of code on a separate line, with the name of the type of code followed by the codes of that type, separated by commas. If a list is empty, the program should output the type of code and ‘None’.
It is assumed that the input is a single line prompting the user to enter a string of digits, and the strings entered consist of only digits. Leading zeros are allowed and need to be accounted for.
An automated testing program will run several tests against the program. Test cases are to be created and the program is to be tested.
The program is to include brief comments in the code identifying the programmer, describing the program and describing key portions of the code.
Code is to be developed with Python 3.9 as the interpreter and executed with PyCharm EDU 2021.1
Source Code
from code_check import *
def show_list(lst: list):
"""
This function prints a list
:param lst: List of elements
:return: None
"""
n = len(lst) # size of list
print("[", end="")
for i in range(n):
print(lst[i], end="")
if i < n-1:
print(", ", end="")
print("]")
if __name__ == '__main__':
# Define the lists to store the code
basic_codes = []
positional_codes = []
upc_codes = []
unknown_codes = []
while True:
""" keep asking for code until user enters 0"""
code = input("Enter code: ")
if code != '0':
if is_upc(code):
upc_codes.append(code)
print(f"Code {code} detected as UPC code.")
positional_codes.append(code)
print(f"Code {code} detected as Positional code.")
elif is_basic(code):
basic_codes.append(code)
print(f"Code {code} detected as Basic code.")
else:
unknown_codes.append(code)
print(f"Code {code} not recognized.")
else:
# Print the current codes saved and then exit
print("Unknown codes: ", end="")
if len(unknown_codes) > 0:
show_list(unknown_codes)
else:
print("None")
print("Basic codes: ", end="")
if len(basic_codes) > 0:
show_list(basic_codes)
else:
print("None")
print("Positional codes: ", end="")
if len(positional_codes) > 0:
show_list(positional_codes)
else:
print("None")
print("UPC codes: ", end="")
if len(upc_codes) > 0:
show_list(upc_codes)
else:
print("None")
break