Python Forum

Full Version: VS Code behaving strangely
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear brains,

So, I know this is a python forum and not VS Code forum, but I know many of you use VS code and may be able to help anyways.

when I open the following code (which is not finished - i know there's some loose ends here and there), I get the expected results: The code chooses randomly a key from the dictionary and print the "inoperation" print functions as expected.

HOWEVER, after that, when I press "play" again (without changes in the script), the exact same lines is generated. Even if I open a new script and press play it will show the same city as before. So is the problem in the code or is there a bug in the VS Code.

Have anyone tried this before?

import random
capitals_dict = {
'Alabama': 'Montgomery',
'Alaska': 'Juneau',
'Arizona': 'Phoenix',
'Arkansas': 'Little Rock',
'California': 'Sacramento',
'Colorado': 'Denver',
'Connecticut': 'Hartford',
'Delaware': 'Dover',
'Florida': 'Tallahassee' ,
'Georgia': 'Atlanta', 
}
states = list((capitals_dict.keys()))
rand_key = random.choice(states)
print (rand_key)
rand_key_value = capitals_dict[rand_key]

phrase = ("what is the capital of ")
a = 0
while a < 1 :
    print (phrase, rand_key)
    choice_user = input()
    if choice_user == rand_key_value:
        a = a + 1    
İmage
The code is fine it picks at random as expected.
So something must be wrong with the VSCode... Strange.
It's ok in VS code, how many times did you run it, as it will pick the same at times.
be aware that your code enters an endless loop at the moment(if you don't enter the same choice) showing the same choice.
I have ran it many times. Also I have changed the text in the print() -> saved -> run and still it is the same, not showing the changes just made. It is as if it freezes after the first run.
Sound like you have it stuck in the while loop, kill the terminal, comment out the loop part and try it.
It might be just that. It seems I always fall into that trap.
Click save all and try again