Existing code
def byteToPercent(byte):
...
return int((byte * 100)/255)
def percentToByte(percent):
...
return int((percent * 255)/100)
Modified code
Add Round() to Return.
def byteToPercent(byte):
...
return int(round(byte * 100/255, 0))
def percentToByte(percent):
...
return int(round(percent * 255/100, 0))
Comparison of results.
Code for comparison.
print(f"|{'before code':^22}|{'after code':^22}|")
print(f"|% to byte | byte to % | % to byte | byte to %|")
print("-"*47)
for i in range(0, 101):
a = percentToByte(i)
b = byteToPercent(a)
c = ptb(i)
d = btp(c)
print(f"|{a:^10}|{b:^11}|{c:^11}|{d:^10}|")
Modifying the code increases accuracy.

The modified code represents exactly 0 ~ 100, 0 ~ 255.
Ex)
input = 70
byte1 = percentToByte(input)
per1 = byteToPercent(byte1)
byte2 = percentToByte_fixed(input)
per2 = byteToPercent_fixed(byte2)
print(byte1, per1, byte2, per2)
---------
Result :
178 69 178 70
Why did I enter 70, but it becomes 69?
Existing code
Modified code
Add Round() to Return.
Comparison of results.
Code for comparison.
Modifying the code increases accuracy.

The modified code represents exactly 0 ~ 100, 0 ~ 255.
Ex)
Why did I enter 70, but it becomes 69?