Skip to content

Tag: python

PyCharm shows unresolved references error for valid code

I am using PyCharm to work on a project. The project is opened and configured with an interpreter, and can run successfully. The remote interpreter paths are mapped properly. This seems to be the correct configuration, but PyCharm is highlighting my valid code with “unresolved reference” errors, e…

Print series of prime numbers in python

I was having issues in printing a series of prime numbers from one to hundred. I can’t figure our what’s wrong with my code. Here’s what I wrote; it prints all the odd numbers instead of primes: Answer You need to check all numbers from 2 to n-1 (to sqrt(n) actually, but ok, let it be n). If…

Allowing resizing window pyGame

I am trying to allow resizing for this app, I put the RESIZABLE flag, but when I try to resize, it messes up! Try my code. It is a grid program, when the window resizes I want the grid to also resize/shrink. Please tell me whats wrong, thanks. Answer You are not updating your width, height, or size when the

Install psycopg2 on Ubuntu

I’m trying to get the python postgres client module installed on Ubuntu 12.04. The guidance is to do the following: However, apt says that the package can’t be located. I’m keen to install this through apt. Is this part of another package that I can install? Answer Using Ubuntu 12.04 it appe…

Why do we need the “finally” clause in Python?

I am not sure why we need finally in try…except…finally statements. In my opinion, this code block is the same with this one using finally: Am I missing something? Answer It makes a difference if you return early: Compare to this: Other situations that can cause differences: If an exception is thr…