PLEASE SOLVE WITH SOFTWARE PYTHON The binary expansion of 1/7 is (0.001001001...
ID: 3817581 • Letter: P
Question
PLEASE SOLVE WITH SOFTWARE PYTHON
The binary expansion of 1/7 is (0.001001001...)2 (repeating). a) Assuming Python also stores 1/7 with 54 digits, how many applications of the operation: x = 8*(x - 1/8) would have to be applied before x was no longer a fraction? (Recall that 1/8 = (0.001)2, while multiplying by 8 moves the binary “decimal point” three places to the right.) b) Verify your answer to part a by writing a short Python function called strange17, taking n as its argument, which applies this operation to 1/7 n times and returns the result.
Explanation / Answer
Answer-a
Subtracting 1/8 , then multiplying by 8 has the effect of removing the first three
decimal places from the expansion of 1/7 . If this number is stored to 54 places, then
54/3 = 18 iterations will remove the decimal expansion entirely. This should result
in x = 0.0
Answer-b
def strange17(n):
x = 1/7
for i in range(0,n):
x = 8*(x - 1/8)
return(x)
When we run this function in Python with n = 18, we do, in fact, get x = 0.0.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.