4. Concepts about variables and assignment

1a = 2
2b = 3
3print(a + b)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 4.1 (cl_l05_4a_en)

4.1. Other alternatives

  • You may wonder why we create two variables, a and b, to add two numbers?

  • We could have achieved the same result in several ways.

1print(2 + 3)
2print(5)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 4.1.1 (cl_l05_4b_en)

  • What is the difference between the first way and the last two?

  • The first case includes the logic we used to obtain the result

  • This way, we explicitly state the algorithm we used mentally to solve this problem

  • In the last two cases, we simply command the computer to print something specific, without making clear the logic to arrive at that result.

You have attempted 1 of 2 activities on this page