Python Number Guesser

Last year, I gave a problem in JAVA to create a number guesser. The idea was that the computer would randomly select a number and the user had to guess the number the computer had picked. http://funmultiplies.com/semester-review-computer-science

This year, in Computer Science 1, we have done a similar assignment in Python. However, in this version, the user is selecting the number and the computer has to “guess” the number the user selected.

On the first day of this project, students had to first choose a solving strategy. The two best strategies were called Hi/Lo Average and Hi/Lo Random.

The idea with both of these is that we ask the user to pick an integer (whole number) between 1 and 100.

With Hi/Lo Average, we take the average of the highest and lowest numbers, in this case 100 and 1 and we get 49. So, our first guess will be 49. If that is too low, then we move the lowest value up from 1 to 48. If 49 was too high, then we would move the highest value down from 100 to 50. We then make our second guess by taking the average of the new highest and lowest numbers. We repeat this process until we get to the number the user selected. The key advantage to this process is that we are guaranteed to solve the problem in 7 or fewer questions.

With Hi/Lo Random, we move the highest and lowest numbers identically to how we did in Hi/Lo Average after each incorrect guess, but we don’t take the average – we just select a random number between the highest and lowest numbers. This can potentially solve the problem very quickly or take considerably longer than Hi/Lo Average since you are entirely dependent upon what integers are selected by a random number generator.

Here is what a possible Hi/Lo Average solution looks like:

#Programmer Name: Eric Evans, M.Ed.
#Program Name: Number Guesser (Hi/Lo Average)
#Program Description: Uses a Hi/Lo Average algorithm to determine the number chosen the user.
#Algorithm: Starts with hi/lo or 100/1. Calculates average of hi/lo. Adjusts hi/lo accordingly after guess. Repeat calculation of average between new hi/lo. Repeat hi/lo adjustment...
#
correct = "N"
#Creates a variable named "correct" and sets the initial value as N
high = 100
#Creates a variable named "high" and sets the initial value as 100
low = 1
#Creates a variable named "low" and sets the initial value as 1
guessCount = 1
#Creates a variable named "guessCount" and sets the initial value as 1
guess = (high + low) / 2
#Creates a variable named "guess" and sets the initial value as the average of high and low
while (correct == "N"):
#Starts a loop that runs as long as the variable "correct" has a value of "N".
  guess = int(guess)
  #Casts the value of the variable "guess" as an integer. This truncates any decimals.
  guessAsString = str(guess)
  #Creates a variable named "guessAsString" and sets the initial value as the value of the variable named "guess" as a string.
  print ("Is Your Number " + guessAsString + "?")
  #Outputs the current "guess" for the user to see.
  response = input("[C]orrect  /  Too [L]ow  /  Too [H]igh")
  #Creates a variable named "response" and sets the initial value as the input from the keyboard.
  if (response == "C"):
  #Start of a conditional statement if the keyboard input is "C".
    guessCountAsString = str(guessCount)
    #Creates a variable named "guessCountAsString" and sets the initial value as the value of the variable named "guessCount" as a string.
    print("Yay! I got it in " + guessCountAsString + " guesses!")
    #Outputs the line displayed when the correct number is guessed.
    correct = "Y"
    #Changes the value of the variable named "correct" to "Y".
  elif (response == "L"):
  #Start of a conditional statement if the keyboard input is "L".
    print ("Too Low Huh?")
    #Outputs an acknowledgement to the user of their input.
    low = guess + 1
    #Changes the value of the variable named "low" to the value of the current guess + 1.
    guess = (high + low) / 2
    #Changes the value of the variable named "guess" to the value of the average of high and low.
    guessCount = guessCount + 1
    #Changes the value of the variable named "guessCount" by adding 1 to its existing value.
  elif (response == "H"):
  #Start of a conditional statement if the keyboard inputs is "H".
    print ("Too High Huh?")
    #Outputs an acknowledgement to the user of their input.
    high = guess - 1
    #Changes the value of the variable named "high" to the value of the current guess - 1.
    guess = (high + low) / 2
    #Changes the value of the variable named "guess" to the value of the average of high and low.
    guessCount = guessCount + 1
    #Changes the value of the variable named "guessCount" by adding 1 to its existing value.
print ("Exiting Program")
#Outputs a message letting the user they are exiting the program.

At the time of the first writing, I omitted the Hi/Lo Random solution as I wanted to see if my students could identify a key weakness inherent in that strategy. Here is a possible Hi/Lo Random solution (I discuss the weakness below):

#Programmer Name: Eric Evans, M.Ed.
#Program Name: Number Guesser (Hi/Lo Random)
#Program Description: Uses a Hi/Lo Random algorithm to determine the number chosen the user.
#Algorithm: Starts with hi/lo or 100/1. Selects a random number between hi/lo. Adjusts hi/lo accordingly after guess. Repeat selection of a random number between new hi/lo. Repeat hi/lo adjustment...
#
import random
correct = "N"
high = 100
low = 1
guessCount = 1
guess = random.randint(low, high)
while (correct == "N"):
  guess = int(guess)
  guessAsString = str(guess)
  print ("Is Your Number " + guessAsString + "?")
  response = input("[C]orrect  /  Too [L]ow  /  Too [H]igh")
  if (response == "C"):
    guessCountAsString = str(guessCount)
    print("Yay! I got it in " + guessCountAsString + " guesses!")
    correct = "Y"
  elif (response == "L"):
    print ("Too Low Huh?")
    low = guess + 1
    guess = random.randint(low, high)
    guessCount = guessCount + 1
  elif (response == "H"):
    print ("Too High Huh?")
    high = guess - 1
    guess = random.randint(low, high)
    guessCount = guessCount + 1
print ("Exiting Program")

If you played the Hi/Lo Random version of the game, you realized that there is nothing in the program to prevent the computer from randomly guessing the same number multiple times. This would need to be addressed by using a data structure to store the guesses and compare them as each subsequent guess was being made.

In addition, the odds are not “favorable” with a Hi/Lo Random game when compared to a Hi/Lo Average game.

Let’s say that the user has selected the number 21 as their number. Now, let’s look at the odds through each run compared side-by-side. I am going to use the random number generator from Google to generate the guesses for this example:

Run # Hi/Lo Average Hi/Lo Random
Guess Odds Guess Odds
1 50 1:100 16 1:100
2 25 1:49 48 1:30
3 12 1:23 17 1:29
4 18 1:11 27 1:8
5 21 1:1 25 1:6
6 N/A N/A 21 1:1

As you can see, with Hi/Lo Random, you are completely at the mercy of the numbers that are randomly generated whereas with Hi/Lo Average, you are guaranteed that your odds are twice as good after each guess.

Deques of Python Stories

I was introducing deques in my Computer Science 1 class today in Python and decided to tell a story around the lesson. I figured I would share as this seemed to sink-in with my classes.

Zara loves Computer Science and using technology. She is hosting a party with several of her friends and wants to have their names displayed on the screen in the order they arrived and then remove them when they depart.

The friends of Zara are:

  • Alice
  • Betty
  • Christy
  • Darla
  • Elizabeth
  • Fran
  • Ginger
  • Holly

Alice, Betty and Christy arrive at the party at the same time and enter in that order.

from collections import deque
myGuestList = deque(["Alice", "Betty", "Christy"])
print(myGuestList)

At this point, we have 3 guests at the party: Alice in index 0, Betty in index 1, and Christy in index 2.

Darla and Elizabeth arrive at the party at the same time and enter in that order.

myGuestList.append("Darla")
myGuestList.append("Elizabeth")
print(myGuestList)

We now have 5 guests at the party: Alice in index 0, Betty in index 1, Christy in index 2, Darla in index 3, and Elizabeth in index 4.

Alice and Betty H-A-T-E Elizabeth. Almost instantly upon seeing her name on the screen, they both leave the party.

myGuestList.popleft()
myGuestList.popleft()
print(myGuestList)

We now have 3 guests at the party: Christy has now moved to index 0, Darla has moved to index 1, and Elizabeth has moved to index 2.

Ginger and Holly arrive at the party at the same time and enter in that order.

myGuestList.append("Ginger")
myGuestList.append("Holly")
print(myGuestList)

We now have 5 guests at the party: Christy is in index 0, Darla is in index 1, Elizabeth is in index 2, Ginger is in index 3, and Holly is in index 4.

Regretfully, Holly had been to another party before coming to Zara’s party and gets sick when she gets inside and has to leave.

myGuestList.pop()
print(myGuestList)

We now have 4 guests at the party: Christy is in index 0, Darla is in index 1, Elizabeth is in index 2, and Ginger is in index 3.

Elizabeth is Holly’s sister and leaves to take care of her sister and possibly ridicule her for her choice of the day.

del myGuestList[2]
print(myGuestList)

We now have 3 guests at the party: Christy is in index 0, Darla is in index 1, and Ginger who has moved to index 2.

Zara realizes that while the computer shows 3 guests at the party, there are 4 guests there. Somehow, Fran came in right after Elizabeth and did not get entered into the computer during the “drama” between Alice and Betty with Elizabeth. Fran needs to be entered into the correct location.

myGuestList.insert(2,"Fran")
print(myGuestList)

We now have 4 guests at the party: Christy is in index 0, Darla is in index 1, Fran in index 2, and Ginger who has moved to index 3.

Zara realizes that there is one person who has been there the entire time, but is not on the list – herself. Since she has been there the entire time, she should be placed at the bottom of the deque.

myGuestList.appendleft("Zara")
print(myGuestList)

We now have 5 people at the party: Zara is in index 0, Christy moves index 1, Darla moves to index 2, Fran moves to index 3, and Ginger moves to index 4.

Everyone, including Zara agrees that the party is pretty lame and that there is a better party down the street. So, everyone is going to leave the party.

myGuestList.clear()
print(myGuestList)

We now have nobody at the party and the deque is empty!

A Real Final Exam: Computer Science

Well, since entering K-12 education in the 2004/2005 school year, I have now written and administered my first “real” semester exams!

While I have always given exams at the conclusion of the semesters, I have never really given a genuine exam “experience”. There would be a test. That test usually consisted of 50 questions. 25 of the questions were True/False and 25 were Multiple Choice. The students were given a single sentence review guide of “Always Be True to Yourself”.

Now, with that as the review guide, I think you could safely guess that the answers were “B” and “True”. Your guess would be correct. Sadly, I did have students fail that test.

The test was not a “give-me grade” since there was usually a major end-of-year project that the majority of their semester grade was based upon. This final was created so we could simply check a box that said we gave a paper final.

This year, I opted to write and administer a genuine rigorous exam as I was not using any major end-of-year projects.

Computer Science (EOY) Final Exam – Test

Computer Science (EOY) Final Exam – Answer Key

As you can see, this is a bit more rigorous of a test. In fact, all of the questions require a calculated answer.

Once the tests are completed, I will analyze student performance in another post.

Spring Exam Exemptions

It is that time of the year again. It’s time for spring semester exams and ’tis exemption season! This is the season when students start seeking if they qualify to be exempt from having to take the semester exam in a given class.

Each school I have had the opportunity to work at does this process differently and each school has used different criteria to determine eligibility for exemptions.

Exemptions (Spring 2017 Finals)
Exemptions (Spring 2017 Finals)

Here, you can see that I have a total of 146 students. There are 88 students enrolled in Business Information Management (BIM) across 4 sections. There are 15 students in my single section of Computer Science I. There are 25 students in my single section of Principles of Technology. There are 18 students in my single section of Robotics & Automation.

As you can see in the chart, 51 of the 88 BIM students are eligible to be exempt from their spring semester exam. This means that 57.9% of my BIM students are eligible to be exempt from their exam!

In Computer Science, that percentage rises to 66.7% are exempt and in Robotics and Automation is continued to climb us to 72.2%!

Unfortunately, in my Principles of Technology, the percentage plummets to 48%. This has been due to poor grade performance because many teams elected to not submit required documentation with their projects throughout the semester.

As Computer Science, Robotics & Automation, and Principles of Technology are stand-alone single-section courses, let’s take a quick look at how each of the BIM sections performed individually.

BIM Exemptions (Spring 2017 Finals)
BIM Exemptions (Spring 2017 Finals)

Here is the break-out of the 4 sections of BIM that I teach.

While the average for all 4 sections of BIM was 57.9%, 1 section performed well above that average, 1 section section performed well below that average, and the other 2 held pretty close to that average.

  • 2(B) has 10 of 23 students qualifying for exemptions, which is 43.4%.
  • 3(B) has 14 of 23 students qualifying for exemptions, which is 60.8%.
  • 4(B) has 14 of 19 students qualifying for exemptions, which is 73.6%.
  • 4(A) has 13 of 23 students qualifying for exemptions, which is 56.5%.

Compared to past years, this is close to what I have experienced as far as exam exemption qualification is concerned.

Flipping Stacks

We are now going to look at how to flip a stack. As was discussed previously, a stack is an ideal method for holding items in a queue such as an incoming call center.

Let’s say the following calls come into a call center. They are time-stamped for reference.

Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22
Call 1 – (972)828-1847 – 2017-02-13 / 08:01:13

In this case, the call that has been placed on hold the longest is “Call 1”, which came in at 8:01:13. However, recall that in a stack I can only interact with the item on the TOP of the stack. In this case, that is “Call 5”.

So, we are going to create a system that “flips” this stack over, pulls the new top item off and then returns to stack to its original order so additional calls can go in the place they should.

So, assuming that we have a stack already created for the numbers, we will need to create an empty temporary stack to hold the items. As we move the items over, the temporary stack will look like the following:

Call 1 – (972)828-1847 – 2017-02-13 / 08:01:13
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57

As you can now see, “Call 1” is at the top of the stack and could be routed to the next available individual. However, if another new call were to come in, the stack would look like the following:

Call 6 – (512)231-1933 – 2017-02-13 / 08:03:19
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57

To avoid our call queue getting mixed-up, immediately following the retrieval of the top item on the stack, we need to move the items from the temporary stack back to the original stack as follows:

Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22

Now, when “Call 6” comes in, it will go where it is supposed to go (following “Call 5”).

Let’s analyze the code for this problem.

//Program Name: Flipped Stacks
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2017
import java.util.*;
public class flippedstacks {
    public static void main(String args[]){
        int count, myStackSize, myTempStackSize;
        Stack myStack = new Stack();
        for (count = 1; count <=10; count++){
            myStack.push(count);
        }
        myStackSize = myStack.size();
        Stack myTempStack = new Stack();
        for (count = 1; count <=myStackSize; count++){
            myTempStack.push(myStack.pop());
        }
        System.out.println("Current Caller is " + myTempStack.pop());
        myTempStackSize = myTempStack.size();
        for (count = 1; count <=myTempStackSize; count++){
            myStack.push(myTempStack.pop());
        }
    }
}

Lines 1 – 4 are the general header information. Lines 5 – 7 are the imports and creation of the class and main object.

Line 8 creates 3 uninitialized integer variables: count, myStackSize, and myTempStackSize.

Line 9 creates a new empty stack named “myStack”.

Lines 10 – 12 push content into the “myStack” stack. It pushes numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, & 10 into the stack.

Line 13 initializes the value of the myStackSize variable as the size of “myStack” using the size function of stacks.

Line 14 is like line 9, but it creates an empty stack named “myTempStack”. This will be the stack that temporarily holds our stack of information so we can get the first record.

Lines 15 – 17 push the content into the “myTempStack” stack by popping each record in the “myStack” stack. The for loop know how many times to do this by using the myStackSize variable that was declared on line 8 and initialized on line 13.

Line 18 displays which caller is the current caller by popping it from the top of the “myTempStack” stack.

Line 19 is like line 13 in that it initializes the value of the myTempStackSize variable as the size of “myTempStack” using the size function of stacks.

Line 19 is also the beginning of the process of reverting the stack back to its original order with the first (oldest) entry removed.

Lines 20 – 22 are similar to lines 15 – 17 but the reverse process. They push content into the “myStack” stack by popping each record in the “myTempStack” stack. The for loop knows how many times to do this by using the myTempStackSize variable that was declared on line 8 and initialized on line 19.

Line 24 & 25 close out lines 7 & 6 respectively.

Arrays with Keyboard Interactivity

Today, we discussed how to create an array with keyboard interactivity. The user will be asked to enter how many numbers they will be entering and then they will be asked to enter numbers separated by a space.

//Program Name: Arrays with Keyboard Input
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2017

import java.util.*;
import java.lang.*;
import java.io.*;

public class arrayKeys {
  public static void main(String args[]){
    Scanner count = new Scanner(System.in);
    System.out.print("How Many Numbers Do You Want to Enter?: ");
    int arraySize = count.nextInt();
    int myArray[] = new int[arraySize];
    Scanner nums = new Scanner(System.in);
    System.out.println("Enter Your " + arraySize + " numbers each separated by a space and press enter when done.");
    for(int counter = 0; counter < arraySize; counter++){
      myArray[counter] = nums.nextInt();
    }
  System.out.println(Arrays.toString(myArray));
  }
}

Following the header information (lines 1 through 4) and the imports (lines 6 through 8), we get to the actual application code.

On line 12, we declare a scanner object named “count” which will receive input from the keyboard.

On line 13, we ask the user to enter the number of items they will be entering. Lines 14 assigns the value that is entered as an integer variable named “arraySize”.

Line 15 creates an empty array named “myArray” which is initialized as the size of the “arraySize” variable declared on line 14.

Line 16 declares a second scanner object named “nums” which will receive the integers to the recorded from the keyboard.

On line 17, we ask the user to enter the integers they want recorded separated by a space.

Line 18 opens a for loop. The loop initialization creates an integer variable named “counter” with the value of 0. The loop condition is to run while the variable “counter” is less than the variable “arraySize”, which was declared on line 14. Each pass through the loop increments the value of the variable “counter” by 1.

Each pass through the loop executes line 19, which assigns the next integer in the sequence of numbers from the “nums” scanner to “myArray” in the index (position) declared by the “counter” variable.

Finally, on line 21, we output the contents of “myArray” as a string.

Tangible Introduction to Stacks

After we spend a day getting back into a coding mindset in Computer Science, we’ll be starting a new unit over data structures. The first structure we’ll be looking at are stacks.

I’m reflecting on something that Dr. Sabrina McCullough used to tell us when she was leading our elementary math training sessions about the importance of introducing a new skill or concept using concrete / real-world / tangible examples.

I applied this when I introduced iterative structures such as for loops, while loops, and do while loops. My students can tell you that I had them walking in circles for a while, but they understood the difference between the types of loops before we ever coded anything!

To start, I am going to have the students tear a sheet of paper into 8 semi-equal pieces. They are going to answer the following questions in this order recording an answer on each piece of paper and stacking them one on the other face-down as they record their answers.

  1. What is your favorite breakfast food?
  2. What is your favorite junk food?
  3. What is your favorite school holiday?
  4. How old are you?
  5. What grade are you in?
  6. What month is your birthday?
  7. What year is it now?
  8. What is your favorite color?

Once the last question is answered, I will have them look at their small stack and ask them the following questions:

  1. As you added a new item to your stack, where did you put it? (top, bottom, or middle)
  2. If you needed to search through your stack for something, where would you start? (top, bottom, or middle)

Next, I will give each student a stack of 8 index cards. The cards will be randomly numbered with the exception of the 3rd card in each stack, which will have the number 25.

Before the students are given their cards, they will be given the rules:

  • Do not do anything with the cards until you are told to do so.
  • You can only have one card face-up at a time.
  • You can only take from the top of the stack.
  • If you perform any sort of calculation beyond a search on a card, that card is removed from the stack and “discarded”.

I will then walk them through a series of exercises with their stack of cards:

  1. Write down the cards in the stack in order.
    Return stack to original.
  2. Search for the card with 25. How many cards were above it?
    Return stack to original.
  3. Take top card and multiply it by 10.
    Discard top card from stack.
  4. Search for the card with 25. How many cards were above it?
    Return stack.
  5. Take top card and multiply by 5.
    Discard top card from stack.
  6. Search for the card with 25. How many cards were above it?
    Return stack.
  7. Write down the cards in the stack in order.
    Return stack.

Once this information has been recorded, the following questions will be asked:

  1. How many cards can we interact with at a time?
    (Answer = 1)
  2. What was the pattern each time you searched for the card with 25 on it?
    (Answer = it was getting closer to the top)
  3. Can we do any calculations with cards below the current top of the stack?
    (Answer = No)
  4. When I place an item on a stack, where does it go?
    (Answer = On the top)
  5. When I take an item off of a stack, where does it come from?
    (Answer = On the top)
  6. How does the term LIFO (Last In – First Out) apply to a stack?
    (Answer = The last item added to the stack is the first item to be removed)

Once we go through this, we’ll then move into basic programming that was discussed in the post http://funmultiplies.com/starting-with-stacks

Hopefully, giving them a tangible example of how a stack works will assist them with the abstract reasoning of working with stacks as a Computer Science data structure.

AP or Dual Credit Computer Science

In addition to Robotics, Computer Science, and Principles of Technology, I teach 4 sections of Business Information Management I (BIM) I. The BIM class is offered as a dual credit course through Navarro College in Corsicana, TX.

While I was completing the credentialing process for Navarro, I noticed that they offer several Computer Science courses that are in-line with our 3 proposed courses. This made me wonder for a moment, is Advanced Placement the best option for our students?

The Case For Dual Credit / Against AP

I have spoken with several different administrators and they are excited about the possibility of offering the Computer Science courses as dual credit as opposed to Advanced Placement.

The reasoning for their excitement is that if the course is offered as dual credit, the student must complete the assigned work and assessments satisfactorily and at the conclusion they receive college credit. Under the Advanced Placement option, the student must do this as well and meet a minimum score of a College Board created/administered exam.

The dual credit solution also allows us to offer Computer Science I, Computer Science II, and Computer Science III as college-level courses. Under the Advanced Placement option, only Computer Science I and Computer Science II would be college-level courses.

In a dual credit scenario, the students will know exactly which college-level courses they are receiving credit for at Navarro College. Under the Advanced Placement option, students have an idea of which courses the Advanced Placement credit will cover but there is no guarantee.

The Case for AP / Against Dual Credit

Having worked for a time in higher education, I have had the chance to see what lies on the other side of the fence. In the world of higher education, faculty are many times admonished if their percentage of “A’s” or passing is too high. This is the concept of grade inflation. Institutions of higher education don’t want to appear that “everyone passes and gets an A!” They have an appearance of academic rigor to uphold.

In the world of K-12 education, we have almost the exact opposite. In K-12, faculty are admonished if their failure percentage is too high. For example, where I am at now, a failure rate above 15% is unacceptable.

As such, let’s look at some grades for 15 fictional students:

  • Student A – 90
  • Student B – 88
  • Student C – 57
  • Student D – 65
  • Student E – 97
  • Student F – 73
  • Student G – 94
  • Student H – 82
  • Student I – 76
  • Student J – 79
  • Student K – 82
  • Student L – 88
  • Student M – 94
  • Student N – 45
  • Student O – 85

In this example, the class average is 79.67% with a failure rate of 20%.

To bring that failure rate down to under the 15% threshold, I would have to find some way to bring the grade of “Student D” up to passing as they are the closest to passing.

If we apply a curve based upon the formula of
grade + (square root (grade) X 0.6)
we get the following:

  • Student A – 90 –> 96
  • Student B – 88 –> 94
  • Student C – 57 –> 62
  • Student D – 65 –> 70
  • Student E – 97 –> 100
  • Student F – 73 –> 78
  • Student G – 94 –> 100
  • Student H – 82 –> 87
  • Student I – 76 –> 81
  • Student J – 79 –> 84
  • Student K – 82 –> 87
  • Student L – 88 –> 94
  • Student M – 94 –> 100
  • Student N – 45 –> 49
  • Student O – 85 –> 91

The class average is now 85% with a failure rate of 13.3%.

So, in the world of K-12 education, this class is now clear of any additional scrutiny of its grades. However, “Student D” who did not demonstrate mastery of the skills has passed.

Let’s assume that “Student D” performs the same way for the entire year – just barely passing due to the curves. This student leaves high school receives college-level credit for the class and believes they are ready for the next-level course, when they are not.

In contrast, an Advanced Placement course could also be held to the same grading guidelines and “Student D” would receive their passing grade in the course. However, to have the possibility to receive college credit, “Student D” would have to score high enough on the College Board exam for that course. Given the performance of “Student D” in the class, they would likely not score high enough to receive college-level credit.

Personal Opinion

I have spoken with administrators at both the K-12 and higher education levels and have come to a final decision.

My initial thoughts are that dual credit Computer Science would be a great solution for my students in the short term as they would be all but guaranteed college-level credit. They would get the “feel good” feeling of receive college credit.

However, in the long-term, I feel that Advanced Placement is the best solution because if counteracts the grade inflation inherent in K-12 education with the College Board exam. Here, the “feel good” feeling of receiving college credit would be genuine as they would have passed an effective 3rd party exam.

As the majority of students taking the class will pursue college after high school, the long-term solution of Advanced Placement seems to be the best option at this time.

How to Make It Better

There are a few different options that could be done to make this better for everyone involved all-around and level the attractiveness of both options for the short-term and long-term:

  1. Remove punitive actions for failure rates in excess of 15% in college-credit classes.
  2. Add oversight to monitor failure rates in college-credit classes and transfer students to non-college-credit classes when justified.
    NOTE: This is already done for many Advanced Placement courses but not Dual Credit.
  3. Genuinely align classroom, campus, and district expectations of college-credit participants (teachers & students) to those of the college that the credit is awarded through.

Starting with Stacks

Our next unit in Computer Science is working with data structures. So far, all we have done is take keyboard input or hard-coded input and done immediate calculations with it. We’ve not actually stored or manipulated any data.

We’re going to start with stacks as those are arguably the easiest data structure to understand.

//Program Name: Starting with Stacks
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2017

import java.io.*;
import java.util.*;

public class stacks {
    public static void main(String args[]){
        Stack myStack = new Stack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        myStack.push(5);
        myStack.push(6);
        myStack.push(7);
        myStack.push(8);
        myStack.push(9);
        myStack.push(0);
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        System.out.println("First Removed Object is: " + myStack.pop());
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        System.out.println("Next Removed Object is: " + myStack.pop());
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        System.out.println("Next Removed Object is: " + myStack.pop());
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        System.out.println("Next Removed Object is: " + myStack.pop());
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        System.out.println("Next Removed Object is: " + myStack.pop());
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
    }
}

As you can see here, we created a new stack on line 11 named myStack and then pushed the integer 1, 2, 3, 4, 5, 6, 7, 8, 9, & 0 into that stack on lines 12 through 21.

Line 22 displays the content of the stack, which at this moment is the following:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

Line 23 uses the search method to display the current position of a searched item, in this case, the integer “1”. Remember, the search method of a stack returns the position relative to the top of the stack. At this point in the application, the integer “1” is located at position 10.

At Line 25, we use the pop method to return the value at the top of the stack. Since this object was handled, it has now been removed from the stack.

Line 26 is identical to line 22 in that it displays the content of the stack at that moment. However, since the top item has been removed from the stack, it now looks like the following:

[1,2,3,4,5,6,7,8,9]

Line 27 is identical to line 23 and provides the position of the searched item, in this case the integer “1” in relation to the top of the stack. Since the top item has been removed, the search item is now one position closer to the top of the stack.

Lines 29-31, 33-35, 37-39, and 41-43 all perform the same functions as lines 25-27. Each time, the top item from the stack is removed, the current stack is displayed, and the position of the searched item in relation to the top of the stack is provided.

Interactive Stacks

Additionally, we will look at adding interactivity to the process as opposed to hard-coding the data.

//Program Name: Starting with Stacks
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2017

import java.io.*;
import java.util.*;

public class stacks {
    public static void main(String args[]){
        Stack myStack = new Stack();
        Scanner myInput = new Scanner(System.in);
        System.out.print("Enter 10 Integers Separated by a Space and Press Enter: ");
        for(int myCounter=1; myCounter <11; myCounter++){
            myStack.push(myInput.nextInt());
        }
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        System.out.println("First Removed Object is: " + myStack.pop());
        System.out.println("Current Stack: " + myStack);
        System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
        System.out.println("");
        for(int myPopCounter=1; myPopCounter < 5; myPopCounter++){
            System.out.println("Next Removed Object is: " + myStack.pop());
            System.out.println("Current Stack: " + myStack);
            System.out.println("Value of 1 is located " + myStack.search(1) + " positions from the top of the stack.");
            System.out.println("");
        }
    }
}

Here, you can see that we’ve streamlined the code considerably. What was lines 25 through 43 is now lines 24 through 29! We utilized a for loop to execute the segment of code through 5 iterations.

In addition, the keyboard inputs are being processed through a for loop located at lines 14-16. This loop runs 10 iterations of the nextInt() method of the scanner object myInput and using the push method of the stack object myStack places them into the stack.

This code runs identical to the code above but the user can enter their own data as opposed to having to utilize the hard-coded data.

Items to Discuss

Next class, we’ll be discussing how the search handles multiple occurrences of the same item. For example, let’s say that a user entered their data to create the following stack:

[1,2,3,4,5,1,2,3,4,5]

In this case, if we used the search method to locate the integer “1”, which integer “1” would be displayed?

We will also analyze the advantages and the disadvantages of stacks as a data structure. This will take us to the next data structure, 1-dimensional arrays.

Semester Review – Computer Science

When my Computer Science I students return in January, I will be giving them the following assignment:

Create a JAVA application that has users guess a pre-selected number as a game. The application should provide the rules of the game which state a random number between 0 and 100 will be chosen and users will be given a maximum of 20 guesses.

When asking the user for each guess, the application should indicate which guess of the 20 the user is on and whether their guess was too high or too low.

If the user guesses the solution in under 20 guesses, they will be congratulated and given the number of guesses it took for them to arrive at the solution.

If the user exceeds the maximum number of allowed guesses, they will be told they have exceeded the allowed number of guesses and will be provided with what the solution was.

While there are numerous ways this problem could be tackled, here is one possible solution that is similar to what I would expect at this point in the year:

//Program Name: Guess My Number
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2016
import java.util.*;
import java.lang.*;
import java.io.*;
public class guessNumber{
    public static void main (String[] args){
        System.out.println("Welcome to the Number Guessing Game");
        System.out.println("");
        System.out.println("I will pick a number at random and your job is to guess the number that I have chosen.");
        System.out.println("The number will be between 0 and 100. I will give you clues after each guess.");
        System.out.println("You will have up to 20 guesses to guess my number.");
        System.out.println("");
        Scanner ready = new Scanner(System.in);
        System.out.print("Are you ready to start? (Y or N)");
        String readyGo = ready.next();
        String readyGoUC = readyGo.toUpperCase();
        if (readyGoUC.equals("Y")){
            double randomNumber = Math.random() * 100;
            int randomNumberInt = (int)randomNumber;
            Scanner myGuessInput = new Scanner(System.in);
            System.out.print("What is your first guess? ");
            int myGuess = myGuessInput.nextInt();
            while(readyGoUC.equals("Y")){
                for (int score = 1; score < 20; score++){
                    if(randomNumberInt > myGuess){
                        System.out.println("Too Low. Try a Higher Number");
                        myGuessInput = new Scanner(System.in);
                        System.out.print("What is your #" + score + " guess? ");
                        myGuess = myGuessInput.nextInt();     
                    }else if(randomNumberInt < myGuess){
                        System.out.println("Too High! Try a Lower Number");
                        myGuessInput = new Scanner(System.in);
                        System.out.print("What is your #" + score + " guess? ");
                        myGuess = myGuessInput.nextInt();
                    }else if(randomNumberInt == myGuess){
                        System.out.println("");
                        System.out.println("Congratulations! You Guessed my Number!");
                        System.out.println("");
                        System.out.println("Number of Guesses = " + score);
                        System.out.println("");
                        System.out.println("Exiting Program");
                        System.exit(0);
                    }
                }
                System.out.println("");
                System.out.println("You have exceeded the maximum number of guesses.");
                System.out.println("");
                System.out.println("The number I picked was " + randomNumberInt);
                System.exit(0);
            }
        } else{
            System.out.println("Thank you for playing.");
            System.out.println("Exiting Program");
            System.exit(0);
        }
    }
}

This solution utilizes several of the skills covered in the first semester of Computer Science I including the use of character, string, integer, double, and scanner variable types. In addition, the toUpperCase and equals methods of the String class are used as is the random method of the Math class.

Also, in this possible solution, if/else, for, and while statements are all utilized along with various Boolean operators.