String.repeat occasionally creates an infinite loop

I put in a really rough fix for this and it's worked for me so far. I have a history midterm tomorrow so this script continuing to work is pretty crucial for me.