Question: Based on the following program: def getChar(): Prints first character of input char = input('Enter a character: ' ) print(char[:1]) def char2bin(a): Converts character input
Based on the following program:
def getChar(): """Prints first character of input""" char = input('Enter a character: ' ) print(char[:1])
def char2bin(a): """Converts character input to binary list""" char2asc = ord(a) asc2binzero = bin(char2asc) string8 = str(asc2binzero[2:]).zfill(8) finlist = list(string8) newlist = [] for each in finlist: newlist.append(int(each)) print(newlist)
def bin2char(list): """Converts a list of bits to a list of characters""" newlist = []; for each in list: newlist.append(str(each)) s = ''.join(newlist) newBin = int(s, 2) newChar = chr(newBin) return newChar
def parityOf(listOfBits, desireParity): """Creates parity bits""" numone = sum(listOfBits) // 1 if ((numone % 2) == 0 and (desireParity == 0)) or ((numone % 2) != 0 and (desireParity == 1)): return 0; else: return 1;
Create a function called appendParity that appends a parity bit to the list of bits.
This function has two parameters: a list of bits, and a desired parity (0 or 1 for even or
odd).
Inside this function call the parityOf function to calculate the parity of the list of bits,
and then append the returned parity bit to the end (the rightmost column) of the list of bits.
Return the new list.
This is what the results should look like:
>>> appendParity([0, 1, 0], 0)
[0, 1, 0, 1]
>>> appendParity([0, 1, 0], 1)
[0, 1, 0, 0]
(The body of this function should be a maximum of 3 lines, but preferably in 1 line.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
