Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Say what the type of each result is, and what value it has. Decide on paper first.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. For each expression, find the types of the parts, and then the rule for the sign.
7 / 2: the sign / always gives a float. The value is 3.5.7 // 2: // divides and keeps the whole number. A whole number divided by a whole number gives an int, 3."7" * 2: text repeated twice is str, "77". It is not the number 14.3 > 2: a comparison gives a bool, True.int("12") + 1.5: int("12") is the whole number 12, and 12 + 1.5 is a float, 13.5.str(3) + "3": str(3) is the text "3", so + joins the two texts. The result is str, "33".Check. Run the program. Each line shows the type and then the value.
Answer: float 3.5, int 3, str 77, bool True, float 13.5, str 33.
Log in to join the discussion.
Loading…