hey @abhaygarg2001 ,
it isn’t any error , actually the thing is that python scripts are generally made for automating stuff , hence from command prompt it doesn’t allow any kind of interruption like from a key or something like this as you want to , because it thinks like you have run something which need to be stopped when it is done.
In place of it, what you can do is, after a particular number of images are saved then you can ask the user whether of he or she want to store more or not. Depending on the answer , you can mode forward or stop it there it self.
I hope this would resolve your doubt.