I2P Design Thinking Programming Challenge

As one of the most prestigious schools in Asia, Hong Kong International School offers a wide variety of extracurricular clubs for students to join in. We want to help students in HKIS access all these clubs easily through an online platform, where they can sign up, read about the clubs, and contact club leaders. This online platform will also provide a quiz that can help students identify what their passion is, conclusively suggesting some related clubs for them.

The first step that we took was to create a questionnaire and survey to see what our customers (students) need. Click here to see the results.

Then we created a list of equipment we needed for this project. This was the list we created:

  • List of all extracurricular clubs, excluding sport teams, the Senate, and any other organizations that should not be accessible simply through signing up.
  • Name and student number of club leaders in these clubs
  • Description of each of these clubs, written by the club leaders
  • Meeting times for each of these clubs and where they meet
  • Any prerequisites or requirements needed to fulfil (such as service credits)
  • Name of teacher sponsor of each club
  • Any posters/pictures of what the club does
  • Age restrictions (if any) of these clubs
  • Equipment required for these clubs
  • Requirements for signups (example: name, student number, grade) If already have a form, attach please

Next, we planned out our algorithm with a flow chart and the pseudo code.

I2P Discover Your Passion Quiz Flow Chart

After many rounds of trial and error, we finally succeeded in making in quiz. This is the final algorithm for the quiz.

function returnLastEntry(){// directing code to specific cell
 var numberOfQ = 10;
 var ss = SpreadsheetApp.openById("1OG1z7x3mZsEzAaH8EJo-4DKq-UMY4wZHzYRfOC6rZqs");
 var sheet = ss.getSheetByName("response1");
 var lastRow = sheet.getLastRow(); //get the last row, e.g. latest response
 var answerSet = sheet.getRange(lastRow,2,1,2+numberOfQ);
 processEntry(answerSet.getValues());
 }
function processEntry(lastEntry){
 //declare the values as local variables in the function
 var scoreLead = 0;
 var scoreService = 0;
 var scoreSTEM = 0;
 var scoreArts = 0;
 var scoreHum = 0;
 var scoreSports = 0;
 var scoreDebate = 0;
 var scoreOther = 0;
//read the email address
 var emailAdd = lastEntry[0][0];
 Logger.log(emailAdd);
 //detects the first character of the cell
 for (var i = 2; i<lastEntry[0].length; i++)
 {
 for (var choice = 1; choice <=10; choice++)
 {
 if (lastEntry[0][i].indexOf(""+choice)!=-1){//adds one point every time it sees the specific number as the first character
 Logger.log("Choice "+choice+" detected");
 if (choice == "1"){
 scoreLead = scoreLead + 1;
 Logger.log(scoreLead);}
 if (choice == "2"){
 scoreService = scoreService + 1;
 Logger.log(scoreService);}
 if (choice == "3"){
 scoreSTEM = scoreSTEM + 1;
 Logger.log(scoreSTEM);}
 if (choice == "4"){
 scoreArts = scoreArts + 1;
 Logger.log(scoreArts);}
 if (choice == "5"){
 scoreHum = scoreHum + 1;
 Logger.log(scoreHum);}
 if (choice == "6"){
 scoreSports = scoreSports + 1;
 Logger.log(scoreSports);}
 if (choice == "7"){
 scoreDebate = scoreDebate + 1;
 Logger.log(scoreDebate);}
 if (choice == "8"){
 scoreOther = scoreOther + 1;
 Logger.log(scoreOther);}
 }
 }
 }
 var scores = [scoreLead, scoreService, scoreSTEM, scoreArts, scoreHum, scoreSports, scoreDebate, scoreOther];
 var keys = Object.keys(scores);
 var max = keys[0];
 for (var i = 1, n = keys.length; i < n; ++i) {
 var k = keys[i];
 if (scores[k] > scores[max]) {
 max = k;//filters out the highest score and identifies which variable has the highest score
var ss = SpreadsheetApp.openById("1OG1z7x3mZsEzAaH8EJo-4DKq-UMY4wZHzYRfOC6rZqs");
 var sheet = ss.getSheetByName("response1");
 var lastRow = sheet.getLastRow();
 var name = sheet.getRange(lastRow,3,1,1);
 var suggestSheet = ss.getSheetByName("response2");
 var suggest0 = suggestSheet.getRange("A1");//referring to specific cells on another sheet
 var suggest1 = suggestSheet.getRange("A2");
 var suggest2 = suggestSheet.getRange("A3");
 var suggest3 = suggestSheet.getRange("A4");
 var suggest4 = suggestSheet.getRange("A5");
 var suggest5 = suggestSheet.getRange("A6");
 var suggest6 = suggestSheet.getRange("A7");
 var suggest7 = suggestSheet.getRange("A8");
if (max == "0"){//sending emails according to categories chosen
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest0.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/leader.html"+" to learn more about these clubs. Thank you!");}
 if (max == "1"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest1.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/service.html"+" to learn more about these clubs. Thank you!");}
 if (max == "2"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest2.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/stem.html"+" to learn more about these clubs. Thank you!");}
 if (max == "3"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest3.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/right-sidebar.html"+" to learn more about these clubs. Thank you!");}
 if (max == "4"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest4.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/publ.html"+" to learn more about these clubs. Thank you!");}
 if (max == "5"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest5.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/active.html"+" to learn more about these clubs. Thank you!");}
 if (max == "6"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest6.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/debate.html"+" to learn more about these clubs. Thank you!");}
 if (max == "7"){
 MailApp.sendEmail(emailAdd, "Club Marketplace Suggestions", "Hello, "+ name.getValues() +". Thank you for filling in the Club Marketplace: Discover Your Passion form. We suggest you try the "+ suggest7.getValues() + " clubs. Visit "+ "https://club-marketplace.github.io/other.html"+" to learn more about these clubs. Thank you!");}
 }}}

Here’s a video of the quiz working alongside with the email.

Along the way, we encountered some errors that we had difficulty solving. This is the testing document for this project.

In summary, here’s a video and slideshow summarizing our project.

To conclude, I thought this project was harder than I expected. There was a simple goal we wanted to achieve, but it took much more to reach that goal. This included learning the basics of JavaScript, learning how Google Script works, and knowing how to manipulate what we know in order to help us achieve our goal. Mia and I worked very well as a team, helping each other at different times. For me, she helped me on the basics of Javascript and I helped her on designing and the content of the website. The workload was evenly split between us, considering that she had to code an entire website and I had to learn an entire new language to code in Google Script. In the end, the effort was all worth it because our end product could potentially help a lot of people in the future.

Click here to visit the website

———————————————————————————-

Semester Reflection: 

In this semester, I would say that I learned more than I expected in Intro to Programming. Even thought majority of our class thought that we spent too much time on the Design Thinking unit, I think that it was worth it. Now reflecting on it, the Design Thinking cycle was worth spending time on because it can be applicable to the real world and is used in many different subjects, such as entrepreneurship and business. Learning Python was also worth the time because I got introduced to the world of code and also got a chance to experience different languages and compare them in this project. In summary, I would definitely recommend this course to other students.

I2P – Online Club Marketplace – Questionnaire

For our summative project, we chose to do a club marketplace. We created a questionnaire about whether the students would like this. Click here to see the questionnaire.

Today, we interviewed around 20 people total. A majority of them were freshmen, but we also interviewed a few upperclassmen. These were the results that we gathered for the multiple choice questions.

Screen Shot 2016-12-15 at 7.38.34 PM Screen Shot 2016-12-15 at 7.38.40 PM Screen Shot 2016-12-15 at 7.38.43 PM Screen Shot 2016-12-15 at 7.38.48 PM Screen Shot 2016-12-15 at 7.38.52 PM Screen Shot 2016-12-15 at 7.38.57 PM Screen Shot 2016-12-15 at 7.39.04 PM Screen Shot 2016-12-15 at 7.39.14 PM Screen Shot 2016-12-15 at 7.39.21 PM Screen Shot 2016-12-15 at 7.39.27 PM Screen Shot 2016-12-15 at 7.39.31 PM

 

 

Here were some results from the open ended questions:

What clubs are you currently in/run?

Do you like the idea of an online club marketplace? If yes, why?

Do you think that an online club marketplace could help you narrow down some choices for clubs? If not, why?

In the next lessons, we plan to use this data to create our mission and design of the product. After designing, we will create a prototype, then test it out and repeat. Once we have something that looks like a final product, we will bring it to the Director of Activities and Co-Curriculum Programs and receive his feedback for further improvement.

I2P – Creating the Makey Makey Challenge

Planning the Makey Makey Challenge: 

With our new learnings about the Makey Makey and it’s ability to work with Scratch, we chose to make a life sized piano keyboard for people to play. The keyboard would include one octave of keys, and the player would need to jump or step on the keys to play a note. Our plan was to get the basic program done in Scratch first, and then transfer it to Python using pyGame.

Lifesized Piano – Materials List/Draft

Lifesized Piano – Mindmap

Lifesized Piano – Flowchart

Lifesized Piano – Pseudo Code

Programming the Makey Makey Challenge:  f4d67a75-1ad0-43a1-91fc-240a989f7a80

Basic Scratch programming for the keyboard. The issue we encountered here was that there was not enough keyboard choices on the Makey Makey board for one octave of piano keys. On the Makey Makey board, there was only 11 keyboard keys, but we needed around 14 for one octave. To solve this issue, we searched online for solutions to changing the key to a function on the Makey Makey board. We found that we had to use Arduino, a programming platform that connects to electronic devices, would be the answer to our question. This website helped us go through the process. Our first step was to download the application Arduino, then download a zip file that included the addon for Makey Makey in Arduino. We did this by dragging the folder within the zip file into the Arduino folder that came with the application, as seen below. This enabled Arduino to work with Makey Makey boards. Screen Shot 2016-12-08 at 10.28.43 PM Screen Shot 2016-12-08 at 10.55.27 PM

Then we downloaded another zip file from the Instructables that held the code and the settings to the Makey Makey board. Following the instructions on the site, we navigated the settings code and changed the function’s key. The video below shows demonstrates how we did it.

Now, we edited the Scratch program to match up with the Arduino settings that we changed. Screen Shot 2016-12-08 at 10.49.30 PM

Constructing the Makey Makey Challenge:

13bb228a-e0a5-475c-ad47-2890d2b2326a

While creating the keyboard for the lifesized piano, we debated back and forth as to how big should the keys be. In the end, we decided to make it about a foot wide to give space for the player to jump on the keys. We also encountered problems with the aluminum foil, since bare feet is moist and easily rips the foil. After the second day, we still have not fixed this issue yet.

Testing the Makey Makey Challenge: 

After doing this Makey Makey challenge, we realised that creating a life-sized piano was not as easy as it sounded. Originally, we thought that we would have to complicate this project more because it sounded too simple. But after encountering the issue of not having enough keyboard keys on the Makey Makey, we knew this was much more complicated than it sounded. With more time, effort, and patience, we think that this project could potentially grow into a project that could help a lot of children interested in music, but do not have the physical capability to reach their full potential.

I2P Makey Makey Balance Board Challenge

Introduction

What is Makey Makey?

Makey Makey is a simple invention that turns everyday objects into control keys for programming. Using the Makey Makey board, alligator clips, and a USB cable, the Makey Makey can hook up to the computer’s Scratch program and read the program from there. Makey Makey is designed for everyone who is willing to apply their creativity to engineering.

Which programs can you use to program a Makey Makey?

In most cases, people use Scratch to program a Makey Makey. Scratch is graphical programming software that is easy to use — click here for the link.

Other projects you could create with Makey Makey.

I would create a piano out of different everyday items, such as coins or pens. If I finished that, I would try to create a control pad for game such as Tetris.

Screen Shot 2016-12-02 at 11.34.04 PM Screen Shot 2016-12-02 at 11.34.08 PM

What went well?

Our simple Scratch program worked and succeeded in resetting the timer whenever the balance board touched the ground. We also managed to create a scoreboard for recording down the seconds that the user managed to stay on the balance board.

What didn’t go so well?

The aluminium foil on the balance board and on the floor kept ripping because people were walking over it or we were handling it too roughly. This caused the circuit to cut off at some times and caused the program not to work. This video was recorded after someone ripped one side of the aluminium foil, so one side of the balance board did not work so well. We fixed it afterwards by using new aluminium foil.

What improvements can you make if you had more time in the lesson?

With time, I think we could’ve recorded down the top three scores. Currently, the computer just lists out the times that the user gets, but it doesn’t sort the scores into top 3. Also, the program right now doesn’t have a stop. If I had more time in the lesson, I would add a stop to after 10 or so tries, and then list out the top 3 scores within those 10 tries.

I2P (S) Geography Quiz

Introduction:

Welcome! This is the page that explains the making of the GGQ – General Geography Quiz. This is a general 15-question geography quiz that I coded using Python. This blog post will bring you through the series of planning, errors, and drafts that I created in order to program the final product. The quiz will bring you through a series of questions where you type in the number corresponding to the answer you think is correct. For example, this is a sample question:

Which continent is Hong Kong located in?

1. North America

2. Asia

3. South America

4. Europe

In this case, the correct answer is 2, Asia. So you would type in ‘2’ after this question shows up. See the video of the working result to see examples.

Mind maps / Flowcharts: 

I2P GeoQuiz MindMapPlanned Version

I2P GeoQuiz MindMap Final Version

Pseudo Code: Planned Version and Final Version

All Versions of the Code:

Comments on the Final Version:

Video of Working Result:

Video of Game (with voiceover):

Testing Document

References / Citations: 

http://effbot.org/ – Lundh, Fredrik. “Effbot.org.” Effbot.org. Django Site, 2009. Web. 25 Nov. 2016.

http://stackoverflow.com/ – Spolsky, Joel. “Stack Overflow.” Stack Overflow. Stack Exchange Inc., 2008. Web. 25 Nov. 2016.

http://www.pythonforbeginners.com/ – “Learn Python by Example.” Python For Beginners. Treehouse, n.d. Web. 25 Nov. 2016.

I2P (S) Quiz Game Lesson 2

General Geography Quiz – Final Version: 

aGlobalVar = 0
def func_mainquiz():
    vName = input(print("Hello there. What is your name?"))
    vAnswer = input(print("I hope you are having a good day,", vName,". Would you like to test yourself on geography? Yes = 1, No = 2"))
    while vAnswer == "1":
        import I2PGeoQuiz
    else:
        print("That’s too bad. See you again!")
        aGlobalVar = 1
print(func_mainquiz())
I2P GEOQUIZ
aGlobalVar = 0
globalScore = 0
vQuestions = open("QuizQuestions.txt")
with vQuestions as questions:
    vLines = questions.read().splitlines()
    #The with statement in Python simplifies the process of opening and closing a text file. Using the with statement, it's easier and more convenient because it opens, reads, and then closes a file
    #splitlines() is a way to separate strings in code. In this case of a text file, it helped get rid of the confusing \n's
def func_q1():
    global globalScore
    vQ1 = input(print(vLines[0:5]))
    if vQ1 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, Vatican City.")
def func_q2():
    global globalScore
    vQ2 = input(print(vLines[5:10]))
    if vQ2 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, Tokyo in Japan.")
def func_q3():
    global globalScore
    vQ3 = input(print(vLines[10:15]))
    if vQ3 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, Tallinn.")
def func_q4():
    global globalScore
    vQ4 = input(print(vLines[15:20]))
    if vQ4 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, South.")
def func_q5():
    global globalScore
    vQ5 = input(print(vLines[20:25]))
    if vQ5 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, Pacific Ocean.")
def func_q6():
    global globalScore
    vQ6 = input(print(vLines[25:30]))
    if vQ6 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, Colorado, New Mexico, Arizona, and Utah.")
def func_q7():
    global globalScore
    vQ7 = input(print(vLines[30:35]))
    if vQ7 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, Nevada.")
def func_q8():
    global globalScore
    vQ8 = input(print(vLines[35:40]))
    if vQ8 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, Ulaanbaatar.")
def func_q9():
    global globalScore
    vQ9 = input(print(vLines[40:45]))
    if vQ9 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, Sydney.")
def func_q10():
    global globalScore
    vQ10 = input(print(vLines[45:50]))
    if vQ10 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, Oceania.")
def func_q11():
    global globalScore
    vQ11 = input(print(vLines[50:55]))
    if vQ11 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, the Nile River")
def func_q12():
    global globalScore
    vQ12 = input(print(vLines[55:60]))
    if vQ12 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, England, Scotland, Wales, and Northern Ireland.")
def func_q13():
    global globalScore
    vQ13 = input(print(vLines[60:65]))
    if vQ13 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, five.")
def func_q14():
    global globalScore
    vQ14 = input(print(vLines[65:70]))
    if vQ14 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is C, United States and Russia.")
def func_q15():
    global globalScore
    vQ15 = input(print(vLines[70:75]))
    if vQ15 == "1":
        print("Correcto!")
        globalScore = globalScore + 2
print("Congratulations! You scored", globalScore," out of 16.")
        print(func_restart())
    else:
        print("Nope. The correct answer is 1, Arizona.")
        print("Congratulations! You scored", globalScore," out of 16")
        print(func_restart())
def func_geoquiz():
    print(func_q1(),func_q2(),func_q3(),func_q4(),func_q5(),func_q6(),func_q7(),func_q8(),func_q9(),func_q10(),func_q11(),func_q12(),func_q13(),func_q14(),func_q15())
def func_restart():
    global aGlobVar
    vRestart = input(print("""Would you like to restart again? Yes (1), no (2)"""))
    if vRestart == "1":
        print(func_geoquiz())
    if vRestart == "2":
        aGlobalVar = 1
print(func_geoquiz())

Final Pseudo Code and Mindmap

unnamed

I2P – Programming Task (F) Adventure Game

Mind map/planning:

unnamed

Pseudo Code:

Drafts:


Final Product:


Final Code:

aGlobalVar = 0
def function_restart():
    global aGlobalVar
    vRestart = input(print("""Would you like to restart again? Yes (1), no (2)"""))
    if vRestart == "1":
        print(funct_game())
    if vRestart == "2":
        aGlobalVar = 1
def function_v3a12():
      v3a12 = input(print("""Do you fight (1) or flee(2)? """));
      if v3a12 == "1":
          print("""You both die trying to kill the wild boar. The End. """);
          print(function_restart())
      if v3a12 == "2":
          print("""You run away, but a herd of pigs corner you, separating you from Piggy. You get gored to death. The End. """)
          print(function_restart())
def function_v3a11():
      v3a11 = input(print("""Do you let Jack share leadership with you (1), or be a dictator (2)?"""))
      if v3a11 == "1":
          print("""You guys split the leadership and he and his choir helps the group hunt, while you and the others help create a signal fire to get rescued. Your leadership seems harmonious and works really well, living long enough to witness a plane see your signal fire and rescue you. You get rescued and return home safely. Congratulations, you’ve survived!""")
      if v3a11 == "2":
          print("""Jack gets jealous and rebels. He and his hunters become more and more uncivilised until they become savages and split from the group. Eventually, out of revenge, Jack and his choir come back and convince your crew that you are a misleading chief. Your group and Jack’s group both set out and rip you apart, until all your remains are washed out into the sea. The End.""");
          print(function_restart())
def function_v3a1():
      v3a1 = input(print("""Accept (1) or decline (2)? """))
      if v3a1 == "1":
          print("""You learn to blow the conch, and when you finally succeed in making a sound, the deep note resonates through the entire island. Over the course of one hour, boys ranging from 6 year olds to 19 year olds stream out of the forest, until eventually an entire choir of boys come out, with a redhead leading the way. All the boys want you to become their leader, but the redhead, Jack, seems to want to be leader too. """);
          print(function_v3a11())
      if v3a1 == "2":
          print("""You and Piggy decide to stay and create a fire, but a wild boar stumbles towards your source of light. """);
          print(function_v3a12())

def funct_game():
   vBeginning= input("You are stuck on a deserted island, "
                      "known to be filled with mysteries of both "
                      "the past and present. You wake up on the beach "
                      "of the island with a chill up your back, and a mysterious "
                      "feeling that you are being followed. You brush yourself off,"
                      " and look around the island. Your stomach is growling, but "
                      "you try to think clearly about your next options. You scratch "
                      "your options into the sand:"
                      "\n" " 1. Go to the faraway abandoned hut"
                      "\n" " 2. Go into the forest "
                      "\n" " 3. Search for people.")
   while vBeginning != "1" or "2" or "3" and aGlobalVar == 0:
       if vBeginning == "1":
           print (" After long contemplation, "
                  " seeing dark clouds hovering over "
                  "the island, bursting to rain, you decide to go "
                  "to the abandoned hut and seek shelter. You enter the "
                  "hut, and notice that it looks empty.")
           vhut= input ("Explore the house (1), or hide in one "
                    "of the rooms and seek refuge just for the night? (2) ")
           if vhut== "2":
               print ("You take refuge in the kitchen and hear a man walk down the "
                       "steps of the hut.")
               vhide= input("Do you greet the man(1), or do you continue to hide.(2)")
               if vhide == "2":
                   print ("You hide, and go to the backyard of his hut. But you walk into a pit of thorns, and bleed to death. You die. The End ")
                   print(function_restart())
                   break
               else:
                   print("The man greets you with a smile and hugs you- a weird embrace especially since you have never met him. However, during the embrace, you still don’t completely trust him, and feel his pocket. A gun shaped indent. ")
                   vgun=input ("Do you take the gun (1), or do you run for your life (2)")
                   if vgun ==("1"):
                       print ("When you take the gun you feel victorious. But as you look around, and see human heads hanging as prizes on the walls, you paralyse. "
                              "You look around, suddenly forgetting that you just stole a gun from a madman. As you look at the room, you realise that the entire room not only has bloody "
                              "human heads but also guns. Not just one gun, but many guns. Too many for your liking. But before you know it, the man shoot you five times. You die. The End.")
                       print(function_restart())
                   elif vgun == "2":
                       print (" You try to run, but realise this was all a dream. The hut had been latched close since you arrived. The man was watching you since you came on the island. "
                              "He chuckles softly, and whispers like the madman he is. Tears streaming down your face, you see him take a knife, and say something about adding you to his pretty collection. "
                              "You stare around the room, and realise all the monuments are dead humans. You have a panic attack, and he kills you when you have fainted. The end, you die.")
                       print(function_restart())
                       break
           else:
               print ("You start to explore the rooms of the house, "
                          "and notice a lot of guns hung up on the walls. "
                          "After exploring all the rooms, and notice that the "
                          "hut is empty, you finally start to relax. You sit in "
                          "one of the lounge chairs in the main part of the hut, "
                          "but the wind blares a chilly breath of air, and you shiver. "
                          "You walk over to the window, and try to close it, but you aren’t "
                          "tall enough. You reach on your tippy-toes and try to close the "
                          "latch. Whilst doing it, you fall out the window, into a pit of "
                          "thorns. The thorns dig deep into your skin, and you bleed to "
                          "death. You die. The End.")
               print(function_restart())
               break
           break
       if vBeginning == "2":
           print("""You get lost. You are scared, and darkness is falling. Suddenly, you fall into a pit with poisonous vipers. You die. The End.""")
           print(function_restart())
           break
       elif vBeginning == "3":
           print("""You pick up a conch shell on the beach. Suddenly, you hear someone calling for you. """)
           v3a = input("""Do you go towards the sound (1), or ignore the call (2)?""")
           while v3a != "1" or "2":
               if v3a == "1":
                   print("""You find a chubby boy with thick spectacles stuck in brambles. You help him out, and discover his name is Piggy. He sees that you have a conch shell, and asks if you know how to blow it. You don’t, and he offers to teach you. """)
                   print(function_v3a1())
                   break
               elif v3a == "2":
                   print("You try to live alone, but you cannot manage to suffice on your own. You eventually die from starvation. ")
                   print(function_restart())
                   break
           break
print (funct_game())

What worked:

– The ‘if’ loops worked well, and the ‘elif’s and ‘else’s worked.

– The idea of putting all the code into one function and then calling up other functions within the main function worked in the end.

What didn’t work:

– At first, the breaks didn’t work and the message that said ‘break outside loop’ kept popping up. This had to do with the issue of indentation and which loop it was stopping.

– Another issue that arose was defining the variables into integers, as the computer would not recognise the integer. We solved this issue by making the integers into strings

– When we added an additional effort of giving an option to restart when the user reached a dead end, we couldn’t figure out how to use functions and variables to do this. In the end, we asked Mr. Lin for help and he taught us how to use the aGlobalVar to define the function for restarting.

– The last issue that we got stuck on was indentation as when we copied and pasted from Google Docs, the indentations kept being messed up.

Who reviewed:

Weilyn, Mr. Lin.

I2P – Python Lesson 5/6 – Reflection

Lesson 5 Input

#function enables you to do things repetition or infinite number of times.
print("""
Line 1
Line 2
Line 3
""")

#Create your own multiple lined message here:
print("""
HKIS..
Intro to Programming
... with Ms. Mok!
""")

#Now try putting this into a function to print off automatically when you need it without repetition
def i2p_intro():
    print("""
    HKIS..
    Intro to Programming
    ... with Ms. Mok!
    """)

print (i2p_intro())

##Functions - Functions must begin with a letter and not contain spaces - variables/functions must be set first
def f_sum(int1,int2):
    """This function will add two numbers"""
return int1 + int2
#main program
vTotal=f_sum(10,15)
print("The total is:", vTotal)

#returning values function
int1 = input("Please choose your first number")
int2 = input("Please choose your second number")
def f_print_largest (int1,int2):
    """This function will print the largest of two integers"""
if int1 < int2:
        print(int1, "is the largest")
    if int1 > int2:
        print(int2, "is the largest")
    if int1 == int2:
        print(int1,"and", int2, "are both equal")

#main program
f_print_largest(int1,int2)

def f_larger (int1,int2):
    """This function will return the largest of the two integers"""
if int1 >= int2:
        return int1
    else:
        return int2

#main program
x = input("Please input your first number")
y = input("Please input your second number")
z = input("Please input your third number")
print((f_larger(f_larger(x,y),z)), "is the larger one")

Lesson 5 Output


Chocolate Machine Input

print("The price of the chocolate bar is $16.90.")
vCash = input("How much are you going to pay?")
vChange = int(vCash) - 16.90
print("You are getting $",vChange, "back")

#vTen is the number of ten dollar bills you have to pay
vTen=int(vChange/ 10)
print("I am giving you back",vTen,"ten dollar bills.")

#vFive is the number of five dollar bills you have to pay
vFive=int((vChange-(vTen*10))/5)
print("I am giving you back",vFive,"five dollar bills")

#vOne is the number of one dollar bills you have to pay
vOne=int(vChange-(vTen*10)-(vFive*5)/1)
print("I am giving back",vOne,"one dollar bills")

#vCent is the number of cents you have to pay
vCent=int((vChange-(vTen*10)-(vFive*5)-vOne)*10)
print("I am giving back",vCent,"cents")

Chocolate Machine Output

Lesson 6 Input:

#Now write a new function that takes two numbers as parameters (inputs )
#and prints out the smallest of the two
int1 = input("Please choose your first number")
int2 = input("Please choose your second number")
def f_print_smallest (int1,int2):
    """This function will print the smallest of two integers"""
if int1 < int2:
        print(int1, "is the smallest")
    if int1 > int2:
        print(int2, "is the smallest")
    if int1 == int2:
        print(int1,"and", int2, "are both equal")

f_print_smallest(int1,int2)

#Now write a function that takes no parameters or returns no values but just prints out "Ms Mok Smells" 3 times
def print_function():
    print("Ms Mok smells"*3)

print_function()

#Now write a function that takes one number as a parameter and returns the number doubled plus one as the output
vnumber = int(input("Please choose a number"))
def f_print_equation(vnumber):
    print(int(2*vnumber+1),

Lesson 6 Mars Bars experiment:

#Function
def f_ask_yes_no(question):
    """Ask  Yes or No Question"""
vResponse = None
    while vResponse not in ("yes","no"):
        vResponse = input(question).lower()
    return vResponse
#Main Program
vQuestion = "Would you like a Mars Bar?"
vAnswer = f_ask_yes_no(vQuestion)

if vAnswer == "yes":
    print("Here is a Mars Bars, I hope you enjoy it")
if vAnswer == "no":
    print("No Mars Bar for you :(")

Lesson 6 Mars Bars Result:

Menu Options Input:

def f_menu_options():
    print("Here is the menu for today"
          "\n1. Appetizer"
          "\n2. Soup of the Day"
          "\n3. Main Course"
          "\n4. Rice or Noodles"
          "\n5. Dessert of the Day")
    vAppetizer = "Here is your appetizer"
vSoup = "Here is your soup of the day"
vMainCourse = "Here is your main course"
vrice = "Here is your choice of rice or noodles"
vdessert = "Here is your dessert of the day."
vChoice = input(print("Please press 1 for appetizer, 2 for soup, 3 for main course, 4 for rice or noodles, 5 for dessert, or 6 for exiting the code"))
    if vChoice == 1:
        print(vAppetizer)
    if vChoice == 2:
        print(vSoup)
    if vChoice == 3:
        print(vMainCourse)
    if vChoice == 4:
        print(vrice)
    if vChoice == 5:
        print(vdessert)
    else:
        print("Thanks for coming, come back soon!")

f_menu_options()

Menu Options Output:

In Python, functions enable you to reuse logic an infinite number of times without repeating yourself. In a way, functions are similar to variables and store information, but instead of just storing strings and values, functions can store loops, strings, equations, and values. Using functions can help you reuse the code easily without having to write out the entire code. Functions are written with the keyword def followed by the function name and parentheses, and then a colon, and these parentheses contain the parameters of the function. Once information is stored into the function, one can easily recall the function by using the function name. For example, in the lesson 5 input, I called the function by saying “f_print_largest (int1, int2)”.

In the Chocolate Machine Challenge, I used my knowledge of variables, simple math, and other functions to create a simple chocolate vending machine. With the given price of $16.9, I let the consumer input how much money they are going to pay, then using that value I find the change required to give, how much ten/five/one dollar bills and cents are required to pay back this change. The result/output is shown in the video.

For Lesson 6, we practiced using functions and defining variables, applying it to real world things like a menu. The menu project has not been finished yet, but that’s what we have done so far.

I2P – Python Lesson 4 (Part 2) – Reflection

Lesson 4 – Code:

##IF ELSE
vScore = 75
#\n = new paragraph
if vScore >= 50:
    print("\nPASS")
else:
    print("\nFAIL")


##IF IN
vMonth = "September"
vLetter = "e"
if vLetter in vMonth:
    print("There is a letter, ", vLetter, ",in", vMonth)
else:
    print("There is NOT a letter", vLetter, "in", vMonth)

vLength = len(vMonth)
print("There are",vLength,"letters in",vMonth)

vChoice = input("Enter Number 1 to 3:")
print()

if vChoice =="1":
    print("Chosen Item 1")

elif vChoice == "2":
    print("Chosen Item 2")

elif vChoice == "3":
    print("Chosen Item 3")
#some unknown value has been entered
else:
    print("Sorry, but", vChoice, "isn't a valid Number,")

input("\n\nPress the enter key to exit")
#"if" is used for the first choice, and elif is used for the rest. For example, if you input 2 for vChoice, then it prints "Chosen Item 2"

Lesson 4 – Code Result: 

Screen Shot 2016-10-25 at 7.46.15 PM

Vowel Score Calculator Code: 

#program that works out the score for a given word
#a = 5
#e = 4
#i = 3
#o = 2
#u = 1
vWord = input("Enter a word: ")

#Convert the word into lower case
vWord = vWord.lower()

#Set score to be 0
score = 0
#Create a loop so that
#letters are looked at one by one...
for letter in vWord:
    if letter =="a":
        score = score + 5
print (letter, "is worth 5")
    elif letter =="e":
        score = score + 4
print (letter, "is worth 4")
    elif letter =="i":
        score = score + 3
print (letter, "is worth 3")
    elif letter =="o":
        score = score + 2
print (letter, "is worth 2")
    elif letter =="u":
        score = score + 1
print (letter, "is worth 1")
    else:
        print(letter, "is worth 0")

#an else, in case the letter is not a vowel
#end of loop
#Print the score
print("Your total score is ", score)

Vowel Score Calculator End Product:

Guess the Word Game Code [so far]: 

import random
vChoices = ("red", "gold", "orange", "green", "aquamarine", "lavender", "fuchsia")
vWord = (random.choice(vChoices))
vName=input("Hi there. What's your name?")

vGuess = input("I have one of the following colours in mind:red, gold, orange, green, aquamarine, lavender, fuchsia . Can you guess which colour?")
vAnswer = len(vWord)
vGuessNumber = len(vGuess)
while vGuess != vWord:
   if vGuessNumber > vAnswer:
       print("This word has less letters than your guess")
       vGuess = input("Try again!")
   elif vGuessNumber < vAnswer:
       print("This word has more letters than your guess")
       vGuess = input("Try again!")
   elif vGuessNumber == vAnswer:
       print("You got it! Well done,", vName, "!")

Pseudo Code for Guess the Word Game:

*Each of the colours have a distinct number of characters

Choose a random word from the list given of the words below.

Set vWord as the variable for the chosen random word.

Set vName as input for “Hi there. What’s your name?”

Set vChoices is equal to the list of words that the computer is going to choose from

Set vGuess as the input for the question “I have one of the following colours in mind: red, gold, orange, green, aquamarine, lavender, fuchsia. Can you guess which colour?”

Set vAnswer as the length of vWord

Set vGuessNumber as length of vGuess

(Create a while loop that encompasses three “if” statements)

While vGuess is not equal to vAnswer:

If vGuessNumber is greater than vAnswer,

Then print “This word has less letters than your guess”

Set vGuess as input for “Try again!”

If vGuessNumber is less than vAnswer,

Then print “This word has more letters than your guess”

Set vGuess as input for “Try again!”

If vGuessNumber is equal to vAnswer,

Then print “You got it! Well done,” vName, “!”

Guess the Word Game Result [so far]: 


In this lesson, we learned about the “If… else” functions and also how the “elif” function plays a part in this. The “if… else” function is used when the condition can either be true or false. If the condition is true, then it follows the ‘if’ statements, and if the condition is false, then the computer follows the “else” statements. For example, in the Vowel Score Calculator Code, the computer reads the “for..in” loop as if there is the letter “a” in the given word, then add five points to the score and say “[letter] is worth 5 points”. If not, or else, then print “[letter] is worth 0 points]. The “elif” function simply has the same purpose as the “if” function, it’s just used to replace “if” functions after the first “if statement”. In the Vowel Score Calculator Code example, after the first “if” statement with the vowel a, we would use ‘elif’ statements to continue with the rest of the vowels. The flow chart for an ‘if… else’ function would look like this:

if_else_statement

A common question arises in the midst of coding: What is the difference, then, between ‘while’ loops and ‘for… in…’ loops? The answer is that they are very different. ‘while’ loops repeatedly execute the given functions as long as the condition is true, because if the condition is false then the code skips over the while loop and continues with the code. In the Guess the Word Game Code, the while loop is used whenever the length of the answer is not equal to the length of the length of the guess. If it is not equal, meaning if the condition is true for this while loop, then the computer will proceed to the following if functions. If the condition is false and the lengths are equal, then the computer will skip over the loop and say good job, or in this case end the code. While loops look like this:

python_while_loop

On the other hand, for loops have the ability to go over the items of any sequence, such as a list or a string. If the given sequence contains something that is wanted, then the computer continues with the execution statement. If the given sequence does not contain something it wants, then the computer skips over the if loop and continues with the rest of the code. In the example the Vowel Score Calculator Code, the computer reads that for every vowel in the word, the computer must proceed and follow the if statements. In this case, for the consonants, the computer would proceed to the else statement. The for loop looks like this:

for loop in Python