for size in [1, 2, 3, 4]:
result = 0
print("size=" + str(size))
for element in range(size):
result = result + element
print(" adding " + str(element)+", result so far=" + str(result))
print("Done. size=" + str(size) + " result=" + str(result))
print("All done!")
I wonder why we use the str()
function on size
and result
in the 7th line. I know we can't use integer and string in a single print function, but if the rule is like this, why isn't there any problem in this code (about integer + string rule)?
x=18
print("Hello , I am" , x , "years old.")
We use integer and string in a single line don't we ?