Basic Concepts - Type Conversion | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Basic Concepts - Type Conversion

In the question below What is the output of this code? >>> float("210" * int(input("Enter a number:" ))) Enter a number: 2 Answers Provided: a) "210210" b) 420 c) "420.0" d) 210210.0 (Correct Answer) If you enter >>> float("210" * int(input("Enter a number:" ))) in the IDLE and use the number "2" as instructed the answer you get is - 2. How do we end up with d) 210210.0 as the correct answer? What I'm I missing?

19th Sep 2019, 5:57 AM
Titus Gitari
Titus Gitari - avatar
2 Answers
+ 2
"210" is string. Multiplying it by integer 2 is 210210 (i.e. Repeating 210 two times) Now, convert it to float resulting in 210210.0.
19th Sep 2019, 6:03 AM
Kuri
Kuri - avatar
0
Thank you for your reply, I wasn't paying attention to the double quotation marks.
19th Sep 2019, 6:51 AM
Titus Gitari
Titus Gitari - avatar