All problems
Code Rate
Problem
Return the rate k / n of a code that encodes k message bits into n code bits. The rate is the fraction of transmitted bits that carry new information.
Hint
An uncoded system has rate 1.
Test cases
case 1
in: [4,7]
expected: 0.5714285714285714
case 2
in: [1,3]
expected: 0.3333333333333333
case 3
in: [1,2]
expected: 0.5
case 4
in: [4,4]
expected: 1
Starter codePython
def code_rate(k, n):
# Your code here
pass4 test cases · run your code against them in the editor