teacher note Teacher note: Conditionals with cards

A misconception that students have about conditionals is that both the statements or blocks under the if and else are executed each time. For instance:

1
2
3
4
if x < 2:
    print("Programming rules!")
else:
    print("This is great!")

Some students think that if x is 1 when the above code is run, the computer will print Programming rules!” and then continue to the else and print “This is great!”. In fact, only one of the statements is ever printed, never both.

Code.org has a great “unplugged” activity called Conditional with Cards which can help students learn the “conditional” execution of code.

Summary

Two teams take turns drawing from a deck of cards. Based on conditions like the card’s suit, color, or value, the teams can gain or lose points, depending on the “program” being run at the time. The game ends when either team reaches a set number of points, or when you run out of cards.

To prepare

1
2
3
4
if Card is Red:
    Award YOUR team 1 point
else:
    Award the OTHER team 1 point
1
2
3
4
if the Card's value < 5:
   Deduct 2 points from YOUR team
else:
    Deduct 2 points from the OTHER team

Directions

  1. Split the class into two teams, say, Team A and Team B. (More fun: have them choose their own team names!)

  2. Shuffle the cards and place the deck in the middle of the room.

  3. Put a “program” up on the board for all to see.

  4. Have the teams take turns drawing cards and “running” the program to see how many points they score each time (keep the score on the board).

  5. At different points in the game, change the program on the board. Do this several times, so students get practice with different types of conditionals.

Wrap up questions

You have attempted of activities on this page