(Please excuse my english skills.)
Hi All! I was working through exercise 5, checked the part ‘What you should see’ and found a difference. The result of the addition, represented by the ‘total’ variable, was quite to high.
If I add 26, 189, and 82.3 I get 2618982.3.
After broking the code I realized it was not summing it up, the variables were just concatenated. I found this in the documentation:
Strings can be concatenated (glued together) with the + operator, and repeated with *
So now I’m confused: The code is doing what it’s opposed to do, but that’s not “What I should see”.
Could you please explain it to me?
My Code:
my_age = ‘26’
my_height = ‘189’ #cm
my_weight = ‘82.3’ #kgtotal = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")
I also tried the code of ex5 with an * between the variables:
total = my_eyes * my_height * my_weight
Because in ex4 there was also nothing repeated when the code was:
carpool_capacity = cars_driven*space_in_a_car
but I got this error:
Traceback (most recent call last):
File “ex5.py”, line 15, in <module>
total = my_age * my_height * my_weight
TypeError: can’t multiply sequence by non-int of type ‘str’
Could you please give me hint, why the code is here acting different than it was in ex4?
(I understand much more than I can express. So, don’t feel needed to simplify.)
Thanks!