Author | Message |
---|---|
Doublenyher
Posts: 5
|
Posted 17:28 Mar 19, 2019 |
On Part 3B it says that if we replace the "1" from 1.__add__(2) to "1.0", it will output the same syntax error but I tested 1.0.__add__(2) and it outputs 3.0. Is there a mistake here or am I doing this incorrectly? Last edited by Doublenyher at
17:29 Mar 19, 2019.
|
kmarlis
Posts: 35
|
Posted 17:54 Mar 19, 2019 |
I do think there's an error with the prompt. Here's a couple of interesting cases 1.__add__(2) does get a syntax error (1).__add__(2) does output 3 1.0.__add__(2) does output 3.0 1..__add__(2) does output 3.0 and here's the most interesting one... 1 .__add__(2) does output 3 (It might be hard to see but there is a space between the 1 and the dot)
I can post the reason why this works this way if you'd like, but I thought I'd give people the chance to discover it for themselves if they want. |
rabbott
Posts: 1649
|
Posted 18:48 Mar 19, 2019 |
Thanks for all those examples! You can also leave additional spaces between the two dots. >>> 1. .__add__(2) 3 Last edited by rabbott at
19:55 Mar 19, 2019.
|
asalin14
Posts: 12
|
Posted 20:48 Mar 19, 2019 |
I think what @DOUBLENYHER was trying to say was that the prompt (mistakenly) suggests that 1.0.__add__(2) will result in error when it does not.
That being said, I think it is clear after @KMARLIS' response that the objective is to figure out why 1.__add__(2) does not work. |
rabbott
Posts: 1649
|
Posted 21:52 Mar 19, 2019 |
Right. I've changed it in the handout. I don't know what I did to get what I thought was that error. |
jungsoolim
Posts: 38
|
Posted 22:06 Mar 19, 2019 |
Also, we can do this 1e0.__add__(2) and these. True.__add__(2) True.__add__(False) Also, 'a'.__add__('1') However, not this 1e0.__add__('1')
|
rabbott
Posts: 1649
|
Posted 22:22 Mar 19, 2019 |
Amazing! |
kverma
Posts: 6
|
Posted 22:38 Mar 19, 2019 |
Here are three more cases :- (1.) .__add__(2) gives output 3.0 (1.0).__add__(2) gives output 3.0 (1.0) .__add__(2) gives output 3.0
|