Jan-01-2021, 07:11 PM
why doesn't python look in two directions
why doesn't python look in two directions
|
Jan-01-2021, 07:18 PM
(Jan-01-2021, 06:39 PM)deanhystad Wrote: I would like to hear what you think this code is supposed to do.Thank you
Jan-01-2021, 07:20 PM
Jan-01-2021, 07:33 PM
(Jan-01-2021, 06:38 PM)Kakha Wrote: if answer is 4before that answer is different from 5 and is not 6 or 7, so Magellanic Clouds... maybe you meant answer >=5 ?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Jan-01-2021, 07:34 PM
(Jan-01-2021, 07:20 PM)ndc85430 Wrote:(Jan-01-2021, 07:11 PM)Kakha Wrote: but short cuts are sometimes wrong The fact is that I was interested to know the principle. there is a short True and there is a long True. Python works with short True. when he sees ! = 5 before Else, it should check == 4 that's all
Jan-01-2021, 07:38 PM
I don't know what you mean by "short" and "long" true. In any case, the interpreter evaluates the code you give it, so since you wrote
q1 != 5 and that was satisfied, that branch was executed. I don't know why you'd expect it to work any other way.
(Jan-01-2021, 07:34 PM)Kakha Wrote: it should check == 4 that's allNo, it should not. elif /esle means that no other condition was True before that branch. And in your case the very first branch/condition is True. As simple as that.Maybe you are confusing if/elif/else construct with switch/case in some other languages where each branch/condition is checked. As mentioned, in python we use dict to implement that functionality.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Jan-01-2021, 07:51 PM
(Jan-01-2021, 07:38 PM)ndc85430 Wrote: I don't know what you mean by "short" and "long" true. In any case, the interpreter evaluates the code you give it, so since you wrote For example, the police arrest a man named "123". There are two of them, and one lives near the police (short truth) and the other lives far away (long truth). who should be arrested?
Jan-01-2021, 07:55 PM
(Jan-01-2021, 07:51 PM)Kakha Wrote: who should be arrested?depends what's written in the warrent (i.e. your code)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Jan-01-2021, 07:56 PM
I have no idea where you're going with that. I'd hope the police make arrests based on evidence.
|
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Python doesn't run! | leon_heller | 2 | 1,317 |
Nov-27-2024, 10:00 AM Last Post: buran |
|
Python IDE doesn't see opencv-python package on my Jetson Nano | sadhaonnisa | 1 | 4,366 |
Oct-11-2020, 01:04 AM Last Post: Larz60+ |
|
Python: command “python -m pip install --upgrade pip” doesn't work | apollo | 2 | 17,217 |
Sep-16-2019, 03:11 PM Last Post: snippsat |
Users browsing this thread: 1 Guest(s)