draw the initial sand for sand in allsand bext goto(sand[ ]sand[ ] print(sandend='' runhourglasssimulation(allsand def runhourglasssimulation(allsand) """keep running the sand falling simulation until the sand stops moving "" while truekeep looping until sand has run out random shuffle(allsandrandom order of grain simulation sandmovedonthisstep false for isand in enumerate(allsand) if sand[ =screen_height sand is on the very bottomso it won' move continue if nothing is under this sandmove it down nosandbelow (sand[ ]sand[ not in allsand nowallbelow (sand[ ]sand[ not in hourglass canfalldown nosandbelow and nowallbelow if canfalldown draw the sand in its new position down one space bext goto(sand[ ]sand[ ] print('end=''clear the old position bext goto(sand[ ]sand[ print(sandend='' set the sand in its new position down one space allsand[ (sand[ ]sand[ sandmovedonthisstep true else check if the sand can fall to the left belowleft (sand[ sand[ nosandbelowleft belowleft not in allsand nowallbelowleft belowleft not in hourglass left (sand[ sand[ ] nowallleft left not in hourglass notonleftedge sand[ canfallleft (nosandbelowleft and nowallbelowleft and nowallleft and notonleftedge check if the sand can fall to the right belowright (sand[ sand[ nosandbelowright belowright not in allsand nowallbelowright belowright not in hourglass right (sand[ sand[ ] nowallright right not in hourglass notonrightedge sand[xscreen_width canfallright (nosandbelowright and nowallbelowright project #