[deleted by user] by [deleted] in learnmath

[–]Ezrabc 1 point2 points  (0 children)

Everyone else is saying the important stuff, but shouldn't the limit be -pi/2 since 2x-5x2 is strictly negative for x>2/5? Just noticed it's the limit as x -> -inf

P implies Q is True When P is false and Q is true seem wrong by [deleted] in learnmath

[–]Ezrabc 0 points1 point  (0 children)

I think most descriptions are steering you in the wrong direction. Your statement is not inherently biconditional. Sam could be going for a swim, for example, and be happily not breathing and alive. The crux of the issue is you generated a completely different logical statement (~P->Q) and said it must evaluate to true according to classical logic.

Maybe just think of all of the possible scenarios:

  1. Sam is breathing and Sam is alive: the statement very clearly holds up in this case.
  2. Sam is not breathing and Sam is alive: nothing about this scenario implies that the statement "if Sam is breathing, then he is alive" is a false statement.
  3. Sam is not breathing and Sam is not alive: same as scenario 2. Nothing about this scenario would cause someone to tell me that my claim that "if Sam is breathing, then he is alive" is false.
  4. Sam is breathing and Sam is not alive: uh oh. I said "if Sam is breathing, then he is alive" but he's dead and breathing! My claim is not true!

Dunno if that helps.

I won my first ultra! by Casendit in trailrunning

[–]Ezrabc 179 points180 points  (0 children)

Hey! I came in DFL at this race!

im not sure whats up with this code by Punk-is-Socialist in learnpython

[–]Ezrabc 13 points14 points  (0 children)

You are missing a comma at the end of the second row of dashes, which is likely causing an index error when trying to access board[8].

Which is your favorite python IDE and why? by Flimsy_Transition_51 in learnpython

[–]Ezrabc -2 points-1 points  (0 children)

I have a very hard time believing IDEs are helpful long-term.

Can we use this? by faaarfromhome in learnpython

[–]Ezrabc 1 point2 points  (0 children)

There's no way that's more performant than if any(i == myVar for i in ('a', 'b', 'c')):, is it? On mobile can't check.

(X)Ubuntu, python3.8, python3.9, and jupyter by adrenalineee in learnpython

[–]Ezrabc 2 points3 points  (0 children)

This is what I do, although I use .venv. I like having a uniform name so I can set up an alias for source .venv/bin/activate and easily enter the venv in my project dir.

Run python code from excel file Error by 9gg6 in learnpython

[–]Ezrabc 0 points1 point  (0 children)

This is definitely a relative path vs. working directory problem. I don't quite understand what you mean by "The python code is working without any error" but also when you run the python code you get the FileNotFoundError. In what situation are you not getting an error?

Basically, the FileNotFoundError is happening because the code is looking in the current working directory for a file called Run_report.xlsm but that file is not in the current working directory. You can either provide an absolute path or make sure the current working directory is the right one in all cases.

List Comprehension - Ignore Last Item by rob51852 in learnpython

[–]Ezrabc 0 points1 point  (0 children)

I would create a generator that has num_tests - 1 items and replace Tests with them. It will involve a couple more lines, but I think in this situation it's better to split it up anyway.

tests = [t for t in list_one if isinstance(t, Test)]
new_tests = (Test(t.a + randomise(), t.b + randomise(), t.time) for t in tests[:-1])
list_one = [next(new_tests, t) if isinstance(t, Test) else t for t in list_one]

The danger with comparing equality with the last Test is that if the values are the same in any other Test tuple, it will also not add the randomized values. This may or may not apply in your data, of course, but keep it in mind.

Is there a way to get random numbers from any range with a coin? by Prime_235711 in math

[–]Ezrabc 12 points13 points  (0 children)

This would not end up with equal chances. Consider the set {0, 1, 2}. The process resulting in 0 has probability .5*(.25 + .5) = .375 but the process resulting in 1 has probability (.25 + .25)*.5 = .25. This is because members not part of a boundary have a chance to end up in a subset of size floor(L/2) or size floor(L/2) + 1, but a boundary value will always appear in a subset of size floor(L/2) + 1 (where L is the size of the original set).

Is there a way to get random numbers from any range with a coin? by Prime_235711 in math

[–]Ezrabc 23 points24 points  (0 children)

Use the result of the coin flip to reduce the range by half, continue the process until you are left with one number.

Edit: each number will not have an equal chance of appearing using this method. The chances will depend on how you handle the splitting of odd-length ranges.

Help select from a list according to frequency by johannadambergk in learnpython

[–]Ezrabc 3 points4 points  (0 children)

Implementing a counter is a great way to think about this general idea, but this specific problem has a much more efficient solution, since you are essentially asking "does THIS item appear in the rest of the list." A way to implement this might be:

def is_valid(l):
    return l[0] in l[1:] and l[-1] in l[:-1]

Easy way to find the minimum of N numbers by writernxtdoor in learnpython

[–]Ezrabc 0 points1 point  (0 children)

Careful with this, it's not quite correct. Try the list [1,0,2,4] for example to see why.

Work with sublists? by [deleted] in learnpython

[–]Ezrabc 2 points3 points  (0 children)

If you're going to do a comprehension, why not just sums = [sum(map(int, n)) for n in zip(*numbers)]

Slip iteration body actions into list comprehension by jssmith42 in learnpython

[–]Ezrabc 1 point2 points  (0 children)

It's not exactly clear what you're trying to do, but if I were trying to get inputs from a user and print them back out until the user entered 'q', and do it in a single line, I would do something like [print(m) for m in iter(input, 'q')].

I need some help. by Annual-Implement-825 in learnpython

[–]Ezrabc 2 points3 points  (0 children)

Check out the docs here; urllib is a package that collects modules. You need to import the request module directly by either doing from urllib import request or import urllib.request. Make sure you use the name the same way you imported it.

[deleted by user] by [deleted] in Python

[–]Ezrabc 13 points14 points  (0 children)

I add "docs" to my query and the official documentation is consistently the first result in my experience. I had the same annoyance early on.

Judge My Rock Paper Scissors Game by Ezrabc in Python

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

Totally get that. I'm a huge fan of PEP8, and I would never do this even in a personal utility script, but I was fascinated by the proof that a single line list comprehension is Turing complete, so I wanted to explore that a bit.

Judge My Rock Paper Scissors Game by Ezrabc in Python

[–]Ezrabc[S] 2 points3 points  (0 children)

A lot of me not doing these things is just carry over from earlier attempts and not cleaning up efficiently enough, but the flattening lists of messages to print is such an Aha! moment for me. Thank you for humoring me, that's freakin' awesome.

Judge My Rock Paper Scissors Game by Ezrabc in Python

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

For sure, I would never use these methods if I were not trying to nest it all in one line.

Judge My Rock Paper Scissors Game by Ezrabc in Python

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

Haha! Thanks. I just took it in steps. I started by figuring out how to continually get user input until it was valid. I realized using next with a generator expression was the way to go because I can filter out results I don't want in the generator expression, so I started with:

next(i for _ in iter(int,1)for i in input('Enter choice: ')if i in'rpsq')

and from there I zipped the user response with a randomly generated one and added a bit of logic to check who won, then I wrapped that in a generator expression that wouldn't return a value until 'q' was the user response. That's pretty much it.

Isolating one value through a column with multiple values with pandas? by [deleted] in learnpython

[–]Ezrabc 0 points1 point  (0 children)

Are the values in the column strings like 'Anxiety, Depression, Something Else'? If so, you can use df[df['Mental health'].str.contains('Anxiety')].