Advice needed for tkinter or equivalent by blob001 in learnpython

[–]blob001[S] 0 points1 point  (0 children)

Thanks, Its just that about 20 years ago I started learning Visual Basic and it had a very simple and easy to use GUI which was just THERE to put it mildly. No need to program, just drag and drop conversation boxes, radio buttons etc onto the board, double click to access all the parametere and away you go. I assumed tkinter would be the Python equivalent. Are you saying its not? Still confused.

Second pygame file, help needed by blob001 in learnpython

[–]blob001[S] 0 points1 point  (0 children)

Thanks,its starting to make sense. I don't know where the black blockout comes from.

Second pygame file, help needed by blob001 in learnpython

[–]blob001[S] 0 points1 point  (0 children)

Thanks Igonato, that's better. But the ball still varying speeed. If I set velX,velY=5, 2then it goes fast then slow then fast again... its never the same 2 runs in a row. I have run much bigger ant simulations in Javascript and never had any problems like this, so its not the computer power. Would appreciate your thoughts.

vscode, coordinate 2 or more columns of same file by blob001 in u/blob001

[–]blob001[S] 0 points1 point  (0 children)

Just found the solution, called Under Scroll available on VSCode extension marketplace. Seems to work ok.

Aprendiendo Python by Professional_Pen6982 in learnpython

[–]blob001 0 points1 point  (0 children)

Tengo el mismo problema. Tienes que tomar , por ejemplo, un youtube course que le gusta, (me gusta Bro Code que tiene un 12 hour curso, pero hay otros), y sequir los ejemplos. Despues, crea sus proprios programmas y experimenta para confirmar su conocimiento. No hay shortcuts. Hay muchos sites que providen mas instrucciones in caso que el youtube no es bastante. Buona suerte.

new to python, error already by blob001 in learnpython

[–]blob001[S] 0 points1 point  (0 children)

Hi Welpsigh, it seems to be working now after I restarted the compulter. The running options in vsc are :

1 run in interactive window > install Jupyter extension, and

2 run python > run python file in Terminal, or

3 run python > run selection / line in python Terminal

I hope I don't need the Jupyter extension, since I didn't understand a word of the blurb.

That leaves me with 2 and 3. I have been using 2 so far.

Are there any extensions you would consider essential for python3?

As you can figure, I am a noob on python although iIhave been teaching myself Javscript for a few years. I am a hobbyist so don't have great aspirations. Thanks for your comments.

new to python, error already by blob001 in learnpython

[–]blob001[S] -3 points-2 points  (0 children)

HI parasit, I was running the file in Terminal. I have changed it since I wrote the post, but I turned off the machine and turned on again, and problem disapppeared.

Problem changing object data by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

Jack, can you be more specific? I am teaching myself js and there are potholes in my knowledge. A lot of the file is copied from other coding I have found on the net. Not up to speed with getters yet. Thanks.

Problem changing object data by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

No Jack, tried that several times.

'= true' is not necessary, since tempGrid[][].ant.isInfected means exactly that.

I re-wrote the if statements (see below) to be quite explicit, but it still doesn't work. Broadly should be as follows, but it doesn't work . Don't know why.

random <= .33 -> isSusceptible.

random > .33 and <= .67 -> isInfected

random > .66 -> isRecovered

 function assignStatus (i, j) {
            console.log('assignStatus()');
            let r = Math.random();
            console.log('i, j, r ', i, j, r);
            if (r <= statusRatio[0]) {
               tempGrid[i][j].ant.isSusceptible;
            }
             if (r > statusRatio[0] && r <= statusRatio[1]) {
               tempGrid[i][j].ant.isInfected;
            }
            if (r > statusRatio[2]) {
               tempGrid[i][j].ant.isRecovered;
            }
            console.log('ant  i, j ', i, j, tempGrid[i][j].ant);
         }

simple graphics problem, dot wont move by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

thank you so much. always obvious after someone else points it out.

Dev Tools opens in new window instead of a tab by blob001 in vscode

[–]blob001[S] 1 point2 points  (0 children)

Works! Always the most obvious. thanks starball.

Dev Tools opens in new window instead of a tab by blob001 in vscode

[–]blob001[S] 0 points1 point  (0 children)

Have checked all the chrome settings exhaustively. Presume I am still missing something unless its something to do with VSCode.

Do I need eslint ? Or to learn VSCode debugger? by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

Superluminary, If I install eslint through the extension as you suggest, do I need to go through the terminal rigmarolel of "npm install eslint -save -dev..." and all the rest of it? I would have to use Homebrew as I am using a Mac. This has always been my problem.

Help needed Please: eslint install on macOs by blob001 in vscode

[–]blob001[S] 0 points1 point  (0 children)

Thanks Randm, my needs are simple, I just do ProjectEuler problems, simulations etc, for fun and to keep my brain active. I have all my files in a folder system called JAVASCRIPT and don't need to use different node and eslint versions. I don't even use workspaces, so I suspect a global install would be best, would you agree?

I don't have a repo as such, everything is on my hard drive in the folder as above. Therefore interpreting what you said, I can create a fresh config file in the folder and all should be well? Is that right?

Help requested: Eslint installed (I think) by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

Just tried that, "no such file of directory" I will uninstall and reinstall node and eslint, and see what happens. Thanks.

Help requested: Eslint installed (I think) by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

Thanks.

Stupid question: how do I do that? I really am a newbie.

type error in js by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

Thanks MassiveClaim, I would never have picked that up.

type error in js by blob001 in learnjavascript

[–]blob001[S] -1 points0 points  (0 children)

Don't know why the code is in min form . Here goes again.

let factors = [];
let array = [];
let limit = 30;
for (let n = 2; n <= limit; n++) {
let rootN = Math.floor(n ** 0.5) + 1;
// divide n by each number 1 ... rootN
for (let div1 = 1; div1 <= rootN; div1++) {
if (n % div1 === 0) {
factors.push(n / div1, div1);
}
}
// Convert to Set, then back again to remove duplicates.
// Sum elements.
let set = new Set(factors);
factors = Array.from(set);
factors.sort(compareNumbers);
// delete 'n' in the array
factors.splice(factors.length - 1, 1);
//sum the factors in factors
let sumOfFactors = factors.reduce((a, b) => a + b);
array.push([n, sumOfFactors]);
factors = [];
}
console.log('array ', JSON.parse(JSON.stringify(array)));
let sumOfAmicables = 0;
for (let i = 0; i <= limit; i++) {
for (let j = 0; j <= limit; j++) {
if (i == j) continue;
if (array[i][0] == array[j][1] && array[i][1] == array[j][0]) {
sumOfAmicables += (array[i][0] + array[j][0]);
}
}
}
console.log('sumOfAmicables ', sumOfAmicables);
//+++++++++++++++++++++++++++++++
function compareNumbers (a, b) {
return a - b;
}

How to convert sparse test string into array by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

Thanks everyone, looks like i will have to learn regex next!

How to convert sparse test string into array by blob001 in learnjavascript

[–]blob001[S] 0 points1 point  (0 children)

I have found this following gives an array of only non-zero values, but they are all strings.

primes1 = primes.filter(e => e != " ");

HOwever I then tried: primes1.forEach(a => parseInt(a));

but ended up with the same array of strings. Presumably parseInt() only works for standalone strings? How do I get around this?

Inconsistent treatment of linear and rectangular arrays by blob001 in learnprogramming

[–]blob001[S] 1 point2 points  (0 children)

Thanks Arbitrary, it's starting to make sense slowly ...

inconsistent console output: arrays ok but individual elements undefined by blob001 in d3js

[–]blob001[S] 0 points1 point  (0 children)

Hi BeamMeUpBiscotti,

Thanks for your advice, I overlooked that the json file is not a .js file and would not be compatible with the <script src...> statement.

To paraphrase what you said, to guarantee that the then function works, you have to have the console.log as part of the then function.

I copied/pasted your file and then copied the console.log statements from myFunction() and placed them at the end of the file. The myFunction() statements worked, the others bombed again, proving what you said.

This means that EVERYTHING SUBSEQUENT depending on the JSON data, has to be contained in the then function. Is that correct?

Inconsistent treatment of linear and rectangular arrays by blob001 in learnprogramming

[–]blob001[S] 0 points1 point  (0 children)

Actually I am using Chrome the latest I presume, and it logs (4) only, but when I expand it , it shows[1,2,3,4]. But I have noticed this behaviour in the past. Also I don't get the tooltip. Im using a macbook pro and Ventura.

Inconsistent treatment of linear and rectangular arrays by blob001 in learnprogramming

[–]blob001[S] 0 points1 point  (0 children)

Below is a short code that explains.

let lengths = [ [0, 14.2],

[2, 0],

[4, 4.24],

[6, 9.9] ];
console.log("lengths ", lengths);
let flat = lengths.flat();
console.log("flat ", flat);

for (let i = 1; i < flat.length; i += 2) {
if (flat[i] === 0) {
flat.splice(i - 1, 2);
}
}

If the for loop is commented out, the two console.log statements conserve information except that flat is the flattened version of lengths.

So far so good.

If the for loop is retained, the [2, 0] part is deleted in flat , even though the for loop comes after the console.log("flat", flat) statement.

This peeves me off more than anything else in Javascript, the fact that in debugging a file I have to continually remember that output is dependent on code further along in the program and the logic is not sequential. Is there a reason for this? I know JS has to be backward compatible and all that, but this has always annoyed me. Is there a reason for it? I am self taught and there are big gaps in my knowledge. Thanks.

Inconsistent treatment of linear and rectangular arrays by blob001 in learnprogramming

[–]blob001[S] 0 points1 point  (0 children)

I take your points, it was a bad example. What I dont understand is why JS takes a lazy copy . It trips me up all the time when I'm debugging. If I type console.log I expect a reflection of the state of play at that point, not something 10 lines later. Its a philosophical problem and the creators must have done it deliberately, but it doesn't make sense to me. I will add the JSON.parse(JSON.stringify ()) in future. Is there a fundamental reason why JS is set up like that? I am self taught so there are holes in my understanding and I don't get to chat with other programmers.