Dhruv Gaba Dhruv Gaba - 5 months ago 6
Python Question

isn't this suppose to run for single time range(3,3,2) python

I am trying to write a prime number program in python. But when user inputs 3. My program is not working. Further checking with print statements i found its not going in for loop.

Answer

I'm going to assume in your program you have range(3,i,2), where i is the input. When your user inputs 3, there will be no range since you're going from 3 to 3.

A good way to fix this is at the beginning of the function. Before you get your range, return [2,3] if the input is 3 (I assume you are doing something similar for 2)

Comments