Secret Number Magic Trick

One way of thinking about programs is as of series of instructions. Here is one series of instructions.:

In [1]:
secret_num = 10
temp = secret_num + 8   #evaluate secret + 8, and put the result
                        #in temp
temp = temp * 2         #evaluate temp * 2, and put the results
                        #in temp
temp = temp / 4
answer = temp - secret_num / 2
print(answer)           
4.0

you can check that the answer is always 4.0, no matter what secret_num starts out being. The series of instructions is actually taken from a magic trick which might be amusing to sixth-grades and Track Ones:

  1. Think of a secret number
  2. Now add 8 to it
  3. Now multiply the results by 2
  4. Now divide the result by 2
  5. Now subtract half your number from the result
  6. You got 4!

Comments

Whatever comes after a # in a line is ignored by the Python interpreter. Things that come after #'s are called comments -- they are inserted to help future you figure out what present you is programming, and also to help whoever you work with on your programs.