### how to write this algorithm in sage?

hello
I want to write this algorithm in sage, but I don't know how to write it as an algorithm in sage, could you please help me

Algorithm : update basis-update of intermediate basis G with reduct h
Given: a finite set G_old ? B[X] and the reduct 0!=h ? B[X]

Find: updates G_new ? B[X] of G_old

begin

1: G_new <-- Ø

2: while G_old !=Ø do

3: selecting from G_old ; G_old <-- G_old {g}

4: if HT(h) not divisible HT(g) then

5: G_new <-- G_new U {g}

6: end

7:end

8: G_new <-- G_new U {h}

9: return G_new

end

thank you so much