+ 2

How does this code have such an irrelevant output?!

the code - spam = "7" spam = spam + "0" eggs = int(spam)+3 print (float (eggs)) expectation 703.0 output- 73.0 why?!

2nd Jan 2017, 5:43 AM
priyanshu
priyanshu - avatar
1 Answer
+ 3
spam = "7" #define string spam with value 7 spam = spam + "0" #add 0 to string spam becomes 70 eggs = int(spam)+3 #convert spam to integer and add 3 became 73. assign new value to eggs print (float (eggs)) #convert eggs to float (73.0) and print it. expectation 703.0 output- 73.0 if you want the output to be 703.0 then then you should make the following change: eggs = int(spam + str (3)) or eggs = int(spam + '3')
2nd Jan 2017, 5:57 AM
Mohamed