jelkner | Good day fkoikoi and tboimah! | 11:55 |
---|---|---|
fkoikoi | good morning jeff | 11:55 |
*** jelkner_ has quit (Remote host closed the connection) | 11:56 | |
fkoikoi | tboimah and I have a question for you | 11:56 |
jelkner | i'll be right back | 11:56 |
jelkner | i needed to change my login method | 11:56 |
*** jelkner has quit (None) | 11:56 | |
jelkner | there we go | 11:57 |
jelkner | i'm back | 11:57 |
jelkner | give me the question fkoikoi | 11:57 |
jelkner | quick as you can fkoikoi | 11:58 |
fkoikoi | why (-2 // 4) is given the answer to be -1 | 11:58 |
jelkner | ah, good question | 11:58 |
jelkner | first, there are two "division" operators in Python 3 | 11:59 |
jelkner | \/ and \// | 11:59 |
jelkner | hmm | 11:59 |
jelkner | they are: / and // | 11:59 |
jelkner | there we go | 11:59 |
fkoikoi | why (2 % -4) is given the answer to be -2 | 11:59 |
jelkner | so / takes to numeric values (int or float) and returns a float | 12:00 |
jelkner | while // takes to int values and returns an int | 12:00 |
jelkner | are you clear on why 15 // 6 is 2, for example? | 12:01 |
fkoikoi | yeh | 12:01 |
fkoikoi | yeah | 12:01 |
jelkner | so 2 // 4 giving 0 makes sense, right? | 12:01 |
fkoikoi | sure | 12:02 |
dcammue | Good morning everyone | 12:02 |
jelkner | great, so the question is, why the seemingly weird behavior of -2 // 4 giving -1, right? | 12:02 |
fkoikoi | yes | 12:02 |
jelkner | it's called "floor division" | 12:03 |
jelkner | and i just did a quick web search and found this: | 12:03 |
jelkner | https://www.pythontutorial.net/advanced-python/python-floor-division/ | 12:03 |
jelkner | take a look at that and let me know if it clears things up for you | 12:04 |
jelkner | you could also ask kevin more when he comes in 2 hours if you are still confused | 12:04 |
jelkner | nice question! | 12:04 |
jelkner | i haven't even thought about the % operator with negatives before | 12:05 |
jelkner | so i need time to think about your 2nd question | 12:05 |
jelkner | The % operator produces the "modulus" (remainder) | 12:06 |
jelkner | so 2 % 4 is 2 because 4 divides 2 0 times with 2 remaining | 12:06 |
jelkner | there is a cool python function called divmod that might help | 12:07 |
*** dcammue has quit (Read error: Connection reset by peer) | 12:07 | |
jelkner | try divmod(15, 6) | 12:07 |
jelkner | what do you get? | 12:07 |
jelkner | quickly please! | 12:08 |
fkoikoi | 2, 3 | 12:08 |
jelkner | great | 12:08 |
jelkner | you actually got (2, 3), right? | 12:08 |
fkoikoi | +1 | 12:08 |
jelkner | what kind of thing is that? | 12:09 |
jelkner | what datatype? | 12:09 |
fkoikoi | integer | 12:09 |
jelkner | nope | 12:09 |
jelkner | it's a tuple | 12:09 |
jelkner | and 2-tuple with 2 ints as elements | 12:09 |
jelkner | the first element is the result of 15 // 6 | 12:10 |
jelkner | and the second is the result of 15 % 6 | 12:10 |
jelkner | the "div" and the "mod" | 12:10 |
jelkner | hence the name, "divmod" | 12:10 |
jelkner | i have to go | 12:10 |
jelkner | but look into that more | 12:11 |
jelkner | do what kevin advised you to do | 12:11 |
jelkner | wonder, explore, play | 12:11 |
jelkner | see you tomorrow morning | 12:11 |
fkoikoi | sure | 12:11 |
jelkner | i'm going to stay logged in so i can catch kevin when he arrives | 12:11 |
jelkner | but i need to prepare for class now | 12:12 |
jelkner | so i'll make myself "away" | 12:12 |
*** Janet has quit (Read error: Connection reset by peer) | 12:29 | |
*** tboimah has quit (Read error: Connection reset by peer) | 12:29 | |
*** fkoikoi has quit (Read error: Connection reset by peer) | 12:29 | |
*** tboimah has quit (Ping timeout: 480 seconds) | 14:04 | |
*** Janet has quit (Ping timeout: 480 seconds) | 14:04 | |
*** fkoikoi has quit (Ping timeout: 480 seconds) | 14:04 | |
*** jelkner has quit (Ping timeout: 480 seconds) | 14:58 | |
*** jelkner has quit (Quit: Leaving) | 15:58 | |
*** shmohamud has quit (Remote host closed the connection) | 21:54 | |
*** shmohamud has quit (Remote host closed the connection) | 21:59 | |
*** shmohamud has quit (Remote host closed the connection) | 22:25 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 23:11 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!