Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions projects/015-parity-bits/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# byte =[]
# x = 0
# u_bit = 'none'

# while u_bit != '':
# x = x + 1
# u_bit = input(f'Insert the bit number {x}: ')
# byte.append(u_bit)


# if x == 9 and u_bit == '':
# n = byte.count('1')
# if n % 2 == 0:
# print('The parity bit is: 0')

# else:
# print('The parity bit is: 1')

# else:
# print('The number of bits must be equal to 8')





# byte = []
# x = 0
# u_bit = None

# while x < 8 and u_bit != '':
# x = x + 1
# u_bit = input(f'Insert the bit number {x}: ')
# byte.append(u_bit)


# if x <= 8 and u_bit == '':
# print('The number of bits must be equal to 8')

# else:
# n = byte.count('1')

# if n % 2 == 0:
# print('The parity bit is: 0')

# else:
# print('The parity bit is: 1')


byte = []
counter = 0
is_error = False

for x in range(8):
u_bit = input(f'Insert the bit number {x}: ')
if u_bit == '':
print('The number of bits must be equal to 8')
is_error = True
break

elif u_bit == '1':
counter += 1

byte.append(u_bit)

if not is_error:
if counter % 2 == 0:
print('The parity bit is: 0')

else:
print('The parity bit is: 1')