Question: def hanoiMoves ( n , frm , to , extra ) : if n = = 1 : print ( f Move disk 1

def hanoiMoves(n, frm, to, extra):
if n ==1:
print(f"Move disk 1 from {frm} to {to}")
return 1
moves =0
moves += hanoiMoves(n -1, frm, extra, to)
print(f"Move disk {n} from {frm} to {to}")
moves +=1
moves += hanoiMoves(n -1, extra, to, frm)
print("Verification of the number of moves:")
for i in range(1,16):
count = hanoiMoves(i,'A','C','B')
count_moves =2** i
assert count == count_moves, f"Error for n ={i}: Got {count} moves, expected {count_moves}"
print("Verification successful: Number of moves matches 2^n for n from 1 to 15.")
keep getting this error:
count = hanoiMoves(i,'A','C','B')
30 count_moves =2** i
--->31 assert count == count_moves, f"Error for n ={i}: Got {count} moves, expected {count_moves}"
32 print("Verification successful: Number of moves matches 2^n for n from 1 to 15.")
AssertionError: Error for n =1: Got 1 moves, expected 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!