Python Forum
VS Code behaving strangely
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VS Code behaving strangely
#1
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
Reply
#2
The code is fine it picks at random as expected.
Reply
#3
So something must be wrong with the VSCode... Strange.
Reply
#4
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.
Reply
#5
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.
Reply
#6
Sound like you have it stuck in the while loop, kill the terminal, comment out the loop part and try it.
Reply
#7
It might be just that. It seems I always fall into that trap.
Reply
#8
Click save all and try again
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020