+ 5

Why int("raja") print some strange number ?

https://code.sololearn.com/cYHl5KN8vpL9/?ref=app

25th Sep 2020, 2:21 PM
Programmer Raja
Programmer Raja - avatar
7 Respuestas
+ 5
Funny Thing :) This number seems to be simply a concatenation of the hex values.. (0x72616A61, where 'r' is 0x72, 'a' is 0x61 and 'r' is 0x6A) I would recommend to use a for loop, to print the ascii values of each individual Charakter...
25th Sep 2020, 2:39 PM
G B
G B - avatar
+ 3
Your code says int('raja'), not int("raja"), but neither of the two were valid candidate for conversion to int anyways. People say garbage in, garbage out, we can't expect a good output when the given input is bad. Just saying ... ¯\_(ツ)_/¯
25th Sep 2020, 2:38 PM
Ipang
+ 3
~ swim ~ What is an example of a valid conversion result from multi character constant to integer? and is there a way to know whether if the conversion result was valid or invalid?
25th Sep 2020, 2:52 PM
Ipang
+ 2
Ipang ~ swim ~ G B Thank you all
25th Sep 2020, 3:25 PM
Programmer Raja
Programmer Raja - avatar
+ 2
~ swim ~ That's alright, I was just asking if there was a way to know if the result was valid. I thought we'd get some error message when conversion fail, but I guess it doesn't have to be (in doubt).
25th Sep 2020, 3:32 PM
Ipang