Monday, October 21, 2019

Coding Functions (age 6)

Benny has been playing coding games where he was using very simple functions.

"Benny I use functions on my computer too! Come see!"

def my_function():
    print("hi Benny")

"This is my function. It says "Hi Benny". It's like the functions in your game. What do you think is going to happen if I call the function?"

def my_function():
    print("hi Benny")

my_function()

Benny laughs.

"What do you think is going to happen if I call the function five times?"

def my_function():
    print("hi Benny")

my_function()
my_function()
my_function()
my_function()
my_function()

Benny laughs loud.

"Why don't I change the name of my function to "say_hi_to_Benny"?"

def say_hi_to_Benny():
    print("hi Benny")

say_hi_to_Benny()
say_hi_to_Benny()
say_hi_to_Benny()
say_hi_to_Benny()
say_hi_to_Benny()

Benny laughs less loud.

"What if I make a function that calls the other function five times? What do you think's going to happen?"

def say_hi_to_Benny():
    print("hi Benny")

def say_hi_to_Benny_5_times():
    say_hi_to_Benny()
    say_hi_to_Benny()
    say_hi_to_Benny()
    say_hi_to_Benny()
    say_hi_to_Benny()

"Nothing happened! Because I didn't call the function. What do you think's going to happen if I call the function?"

def say_hi_to_Benny():
    print("hi Benny")

def say_hi_to_Benny_5_times():
    say_hi_to_Benny()
    say_hi_to_Benny()
    say_hi_to_Benny()
    say_hi_to_Benny()
    say_hi_to_Benny()


say_hi_to_Benny_5_times()

Benny laughs but I can tell he's losing interest so we stop there.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Cialdini's Social Proof (Age 8)

 I want to teach Benny about "social proof" in Robert Cialdini's Influence: The Psychology of Persuasion . Social proof is bas...