import random MAX_ELEMENTS = 25 # Each character is assigned a numeric (ASCII) code e.g. A = 65, B = 66 # a = 97, b = 98... { = 123... # For the extended code set: https://www.ascii-code.com/ MIN_CHAR = 33 MAX_CHAR = 126 # args(none) # return(a randomly generated character) from ! to ~ def generateElement(): #Declare variables for function aChar = " " dieRoll = -1 dieRoll = random.randrange(MIN_CHAR,(MAX_CHAR+1)) aChar = chr(dieRoll) # Function to convert ASCII code to a character return (aChar) # args(none) # Creates a list of 1 - 100 elements each element a string of length 1 # return (reference to the list) def createList(): #Declare variables for function aList = [] size = -1 i = -1 size = random.randrange(1,(MAX_ELEMENTS+1)) i = 0 while (i < size): aList.append(generateElement()) i = i + 1 return(aList,size) # args(none) # displays an index followed by each list element on it's own line # return(nothing) def display(aList,size): #Declare variables for function i = -1 i = 0 while (i < size): print("Element at index[%d]=%s" %(i,aList[i])) i = i + 1 # args(reference to a list) # Function counts and returns the number of instances of a character that is # entered by the user found in the list. # return(integer) def count(aList,size): #Declare variables for function count = -1 i = -1 aChar = "" i = 0 count = 0 aChar = input("Enter the character that you want a count of in the list: ") while (i < size): if (aChar == aList[i]): count = count + 1 i = i + 1 return(count) #Starting execution point for the program def start(): #Declare variables local to starty aList = [] size = -1 aList,size = createList() display(aList,size) print(count(aList,size)) start()