Thanks to the help of reddit /r/learnprogramming I was able to understand what I did wrong with my code and learned how to solve the problem