Skip to content

Pedagogy of Teaching Programming

August 27th, 2021 by PostPcEra

Pedagogy realted

0. Big Picture

Language choice : Python vs. JavaScript

  • may be JS is better in 2022 than python, as web became dominant programming platform
  • let us use Mozilla JS Guide here
  • Online compilers : we need PURE JS compiler with out HTML/React embeded since we are teaching Javascript language, not WebDevelopment.
  • programirz JS - It is exeuting on Server and sending results back.
  • penEditor
  • we have other Pure JS editror saved in github .. They behave like above Programirz, see we saved those github repo names in Notion Notes.

1. Basic concepts

It is like Math word problems:

  • how you solve math word problems . A room has lenth of 10 feet and width as 8 feet, wheat is the area of the Room.
length = 10 feet
width = 8 feet
area = lenth * width
area = 10 * 8
area = 80 square feet
volume = lenth * width * height // what happends if you do math this way
  • we do same in computer programming
  • Memory box concept
  • explain about area problem with memory box . A memory box has a storage and Lable, Lable is the name how you remember what is stored in it.

2. Control Flow realted Problems

IF ELSE

  1. find the SMALLEST of two numbers
// which one of these two you like and why ?
// -----------------------
def smallest_of(a,b):
if (a < b )
smallest = a
else:
smallest = b
return smallest
// -----------------------
def smallest_of(a,b):
smallet = a
if (b < smallest )
smallest = b
return smallest
  1. find the SMALLEST of three numbers ( same logic goes for Biggest )
def smallest_of(a,b,c):
smallet = a
if (( b < smallest) and ( b < c))
smallest = b
else:
smallest = c
return smallest

Low Cyclometric complexity ( Low CC is better )

smallet = a
if ( b < smallest)
smallest = b
if ( c < smallest)
smallest = c
def min_of(a,b):
min = a
if ( b < a)
min = b
return min
#--------------
def smallest_of(a,b,c):
return min_of(min_of(a,b), c)

3. Loops n Variations

simple loops

Note : a) when building on top of peers problem, have student do OTHER way ( if original is WHile , modify it to FOR and vice versa )

Type 1: While Loop , two Loop conditions, how to split them, FOR and While interchange

Type 2: asking user input in a loop

  1. Simple While loop is
# calculate sum of numbers 1 to N ( first give with out List)
number = 6
sum = 0
current_number = 1
while (current_number <= number):
sum = sum + current_number
current_number = current_number + 1
print(sum)
# calculate and return the SUM of the all the elements in a given List
def calculate_sum(list):
index = 0
sum = 0
length = len(list)
while (index < length):
sum = sum + list[index]
index = index + 1
return sum
  1. Now, we want to calculate SUM of first N elements in the List, not all the elements of the List
// calculate and return the SUM of the First K elements in a given List
def calculate_sum(first_k, list):
index = 0
sum = 0
length = len(list)
while (index < length): # O(n)
if (index < n_elements):
sum = sum + list[index]
index = index + 1
return sum
  1. now combining the condition of While loop, Time Complexity is reduced to O( small_of(n,first_k) )
while ((index < length) and (index < first_k)): # O( small_of(n,first_k) )
sum = sum + list[index]
index = index + 1
  1. now combining in the condition of While loop with Break statement
# two conditios in WHILE Loop ( in above problem) are broken into sequence of two Separate conditions
while (index < length):
if (index >= first_k): # O( small_of(n,first_k) )
break
sum = sum + list[index]
index = index + 1
  1. using FOR Loop and Break
for num in list:
if (index >= first_k): # O( small_of(n,first_k) )
break
sum = sum + num
index = index + 1
  1. using infinite loop

we need ASK students to write each problem at least 3 differnt ways, why? : that is how student Mental FOG is removed and the NURON conections are Strengthed. I saw same approach of TWO different ways solving MATH problem in COMMON CORE text books.

while (True):
if (index >= first_k): # O( small_of(n,first_k) )
break
sum = sum + num
index = index + 1

4.using Booleans

created date : 3/3/2022

simple Booleans

  • you are spending on day1 10 , day2 20 , day3 10 , day4 20 repeteldy till your pocket money is out
  • write function to print day #, spent, remaining money
  • use boolean

3 day pattern spenindg

  • same as above with chane day1, day2, day3 : 10,20,30 and it repeats
def pocketmoney(amout):
spend = [ 10, 20 ,30]
daycycle = 1
day = 1
balance = amout
while ( balance > 0):
todayspending = spend[dayclycle]
balance = balance - todayspending
if balance < 0:
break
print(day, todayspending, balance)
day++
if daycycle == 3:
daycycle = 1 // reset
else:
dayclycle++ // increment

odd even sum

  • write a function to print total sums of even and odd numbers from 1 to N
def oddevensum(n):
// print oddsum , evensum
oddsum, evensum = 0,0
i = 1 ;
oddelement = true
while ( i <= n): // no FOr loops in first one month of coding :-)
if (oddelement):
oddsum += i
else:
evensum += i
oddelement = !oddelemet // toggle each time
i++
print here ///
// ---------- main program
oddevensum(10)

Chess Tournment scores

  • Leaners needs to understand how to apply the concepts of Boolean in a program code, here is a way
  • Problem statement : Anna and Bob played a chess tournament consisting of 5 games. Design your data structure and write a program to print 'Winner'
  • Here learner needs to think and comeup with his own data structure of INPUT data.
def showwinner (gamedata):
// print <Anna/Bob> is Winner or Game is draw
scorelist = gamedata[1]
len = len(scorelist)
annatotal, bobtotal = 0,0
i = 0 ;
oddelement = true
while ( i < len):
if (oddelement):
annatotal += scorelist[i]
else:
bobtotal += scorelist[i]
oddelement = !oddelemet // toggle each time
i++
str1 = 'Tournment is draw '
str2 ]= ' with scores at Anna: Bob {} : {}',
if annatotal == bobtotal :
print( str1 + str2 )
elseif annatotal > bobtotal :
print( 'Tournement Winner is Anna,' + s2 )
else:
print( 'Tournement Winner is Bob,' + s2 )
// main program
gamedata = [ ['Anna', 'Bob'] , [ 1,0, 0,1, 0.5,0.5, 1,0, 0.5, 0.5 ]
showwinner(gamedata)

different ways of representing data

  • ask students to disign data structure in multiple ways for the same Chess problem
  • ask to write what are the Pros and cons of each method
- [ ['Anna', 'Bob'] , [ 1,0, 0,1, 0.5,0.5, 1,0, 0.5, 0.5 ]
- [ ['Anna', 'Bob'] , [ [1,0], [0,1], [0.5,0.5], [1,0], [0.5, 0.5] ]
- [ 'Anna', 'Bob', 1,0, 0,1, 0.5,0.5, 1,0, 0.5, 0.5 ]
- [ Anna, Bob, 1,0, 0,1, 0.5,0.5, 1,0, 0.5, 0.5 ] // no quotes Tournement volunteers just do basic data entry
- { ['Anna', 'Bob'], [1,0, 0,1, 0.5,0.5, 1,0, 0.5, 0.5] }
-{ {'Anna' : [1,0, 0,1, 0.5] }, {'Bob': [0.5, 1,0, 0.5, 0.5] } }

popular movie based on user rating

  • a class gave their rating for movies students saw in last 6 months, print the top 3 popular movies
  • ask student to comeup with data structure
  • one such format is a flat file ( like Gitu UCSC assignment)
'super man'
5
'bat man'
4
'super man'
4
'movana'
6