Logical Coding Problems Python