Skip to content
Open
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions projects/015-parity-bits/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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 != '':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you find a way to optimize the while loop?

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')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is possible to avoid this count?


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

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