If your not savvy in computer programming, or specifically, savvy in Python, you probably would not be able to figure out the answer to this question. But the answer is simply:
“210” is a String. * means multiply, in which its multiplying in this case to an integer. Int is short for integer. Input means to take from a user’s entered value. The question the user is asked is, “Enter a number:”. In this case, the user enters 2. Since the user’s input is 2, and the math is a String * an integer; in other words, “210” * 2. The answer is 420. But not… “210” is a String, like words, not an actual number in this case. No its not 210210 either. Actually, what about the float? Well, if look at this as a math problem, you do all inner parenthesis first. The >>> doesn’t mean anything here other than awaiting a user’s command. The float means, simply, allow numbers from being solely integers to being values of decimals. So, its not just 210210, its actually:
float(210210)
Therefore, the actual correct answer is:
210210.0
Crazy right?
After going through a series of other questions while learning Python, I decided to start writing up the questions in a python script. This way I can test the code to see what it does before I give my answer. Yea, its sorta cheating, but not if your understanding why the code does what it does.
[The question about was a screenshot from SoloLearn.]
I love this post. I want more.
LikeLike