Skip to content
Advertisement

How do I update a variable that is pulling randomly from a list using python?

I am trying to make a small flash card program for my kids. Here is what I have come up with so far, I was hoping if I reassigned the variables in the button function it would randomly pull a new list item. But that does not seem to be the case. I know my code is not he prettiest, I’ve been teaching myself how to code for about 3 weeks now, so if there is anything else anyone can recommend to help improve this I would appreciate it.

JavaScript

Advertisement

Answer

There were two problems that were stopping your code from working, so I’ve listed them below.

Firstly, your ‘rx’ and ‘ry’ variables inside your “press” function for generating a new flash card were local, which means they only worked inside the function and didn’t change the values outside of the function. I put the ‘rx’ and ‘ry’ variables you created at the top inside an array so you can alter them inside a function and have the changes stay.

Secondly, there was a small error inside your second “press” function where you didn’t use “config()” on “top”, “operator”, or “bottom”. I fixed that.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement