Question
Python coding, please do without importing modules :) Write a function, encode, with one parameter, letter, a string. encode will add a parity bit to
Python coding, please do without importing modules :)
Write a function, encode, with one parameter, letter, a string. encode will add a parity bit to the binary (ASCII) representation of letter. The parity bit should be the most significant (leftmost) character. The new binary representation will be returned. For example,
>>> encode('c') # binary representation of 'c' is 1100011
'0 1100011' # with parity bit leftmost 0
>>> encode('d') # binary representation of 'd' is 1100100
'1 1100100' # with parity bit leftmost 1
Function encode will call another function,parity, to determine the parity bit (0 or 1) for a binary sequence (for 1- bit even parity). F unction parity will have one parameter, bitrep, a string which is a sequence of 0s and 1s, and will return a 1-character string, the parity bit. For example,
>>> parity('1100011') # binary representation of c
'0' # parity bit is 0
>>> parity('1100100') # binary representation of d
'1' # parity bit is 1
Next write function decode, with one parameter, pletter, a string representing the binary sequence, plus parity bit, for a character. Decode should call function parity, to check for even parity in pletter. If no error is detected, decode should convert pletterback to a character, and return the character. If an error is detected, decode should return'*'.
Finally, write a main function that encodes and decodes the characters is a word. For example,
word = 'cat'
for letter in word:
print(decode(encode(letter)), end='')
print()
The last line in your .py file should be a call to function main:
if __name__ == '__main__':
main()
As much explination as you go through your code what be great!
this is what i have so far...
def encode(letter):
letter_to_asc11 = ord(letter) add_binary = bin(letter_to_asc11) #print(add_binary) add_parity = bitrep parity(bitrep)
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