Library Check in/Check out system

The Library check-in/checkout system is a program that keeps track of an inventory of books where a User can check out books. I decided to model this system after a simple classroom library system where there’s a log that tracks when someone checks out or returns a book. At first, I wanted to make a program that did the following:

  • Record every item checked out/returned
  • Keep track of items available
  • Record student logs

The classes in the program I wanted to write:

Classes

Inventory

 

  • Properties

 

    • Contain List of Books

Book

 

  • Properties

 

      • Pages *later
      • Descrip *later
      • ID *later
      • Title
      • Author
      • Genre

 

  • Actions

 

    • Getters

 

User (Interface)

 

  • Properties

 

      • Name
      • ID

 

  • Actions

 

    • Checkout
    • Return
    • View Inventory

 

Admin (Subclass of User)

 

  • Properties

 

      • Admin ID

 

  • Actions

 

    • Check all students logs
    • Check users

 

Student (Subclass of User)

 

  • Properties

 

      • Student ID

 

  • Actions

 

    • Log (Checkout/Return date, Book)
    • Search by Genre/Author/Title (Overrides View Inventory)

During the process, the biggest challenge I encountered was making the system where the user could input the information. I used Scanners so the user could type in the console, and I had trouble having the program read the right input. I solved the problem by switching from scanner.nextLine() to scanner.next(). The only problem with this was scanner.next() only read the next token and not white spaces. I tried to use delimiters but I wasn’t able to make it work. Another problem I had was getting specific parts of the program loop. Since I wanted the program to run until the user chooses to quit, I needed to enclose everything in while loops so the code wouldn’t just run once and its over. Lastly, one of the challenges was trying to figure out which variables to put in the classes. Since I had a Book class, Admin, Student, User, Inventory, Select, I needed to decide where each variable goes and whether they were static or private.

Student Field Variables:

Student Constructor (also sets student ID depending on grade)

User (super of Student) Return and Checkout book methods

Book class, has attributes of a book and getter methods

Select class which displays the user interaction part using Scanners.

 

Encryption using String Class

For this assignment, we had to make three classes, ImitationGame, Cipher, and Decipher. Originally, I wanted my code to first go through the String character by character and have the program convert each character in the String to an encrypted Index. So I first made the “cipherbet” to be “cipherstuvwxyzabdfgjklmnoq” and I started off by writing a for loop. I wanted the code to read each character and translate them to their respective position on the cipherbet, so I needed the String method indexOf() to find the position of the letter in the alphabet, and charAt() to use that position to find the character on the cipherbet. As for deciphering, there is no change, besides switching the order of the alphabet and cipherbet.

There was a problem with using an index because the index needed to include all special characters, so I needed to use ASCII code. Same as the cipherbet, I would start off with a for loop that goes through each character. Then, I would use charAt() to find the character in the String and convert to an int, which is ASCII code. Since I’m doing a Caeser shift, I would do:

I also wanted to add a substring() method so I decided to take half of the String and switch with the other half (ABCDEF –> DEFABC). I used length()/2 to find half of the String, but there was a problem. For even-numbered character length Strings, it would divide evenly but odd-numbered Strings would round down. I used an if statement to check if the String’s length was odd, and if it was it would do (length()/2) + 1.

For deciphering, there was no need to check for even or odd, because since it rounds down, it would match perfectly with the rounding up for cipher. ABCD   EFG —> EFG   ABCD. In my github, I have Cipher and Decipher classes as the one with index and CipherSub and DecipherSub classes as the one that uses ASCII. I’ve also added some text to the main method that uses the Scanner class to take in user input.

Github

 

Schoology User Project

For this project, I made a User class, a Student subclass, and a driver class with the main method. The User class has field variables userName and status with 5 methods: getUserName, setUserName, getStatus, setStatus, printUserInfo. The student subclass inherits the methods from the User class and has a method: printStudentInfo(). The main method makes three objects: peter, mary, and john and prints their info.

The Matrix and OOP

In this scene, try to explain what’s happening in Cypher’s mind when he “tasted” the beef. How is it similar to a class and an object?

When Cypher tasted the beef, he thinks that the beef is delicious. Cypher’s mind is like the computer and the beef is the class. The class is a blueprint for the beef and the flavour of the beef is one of the objects. The class beef consists of many objects that tell Cypher the texture, taste, size, etc, of the beef.

 

Are the guns in this scene “real”? What was the operator doing in this scene for Neo and Trinity? Explain the processing using the OOP concept.

In OOP, you have classes and objects and are trying to define them. The operator creates racks of guns in the space when Neo tells him to. Unlike non-OOP, Neo does not create the guns but instead have the operator to do it for him. This way, Neo doesn’t need to make all the guns one by one but instead, he can just call the gun method and the operator will make the guns.

 

What is the “Construct”? In java there’s something with a similar name called  constructor”. Describe both the “Contract” (In the movie Matrix) and the “constructor” in Java language. Explain the function of a “contractor” in a class.

Constructors are there to create an instance of a class. They cannot return any value and are different from methods. In the movie Matrix, the construct was a place where Morpheus could create any object. The constructor will set up and create an object, like how Morpheus did in the Matrix. Morpheus can then assign values and initiate these objects through the constructor’s help.

Design Thinking Programming Challenge

 

 

unnamed

 

Flowchart:

Design thinking questionnaire:

At the start of the project, we interviewed many different teachers instead of making a google form, so we recorded some response. We decided to go with the librarian’s idea.

Librarian:

What forms of technology do you use in the library?

Macbooks, iPads, tv monitors, touchscreen display, checkout system.

What technical difficulties did you face?

The library is fine since the technology is only installed if it works perfectly. However, we would like to improve the library checkout system to a self-checkout system. Some kind of scanner, maybe a fingerprint scanner or face recognition app to put on our screen so we don’t have to type in the student number every time.

Design Thinking Process:

In the beginning of the class, Harry and I went around the school to conduct interviews. Our goal was to resolve various issues around the school and we needed to talk to teachers in order to emphasize with them. The first teacher we went to was the middle school PE teacher Mr. Coleman. Mr . Coleman really wanted to implement new technology into his PE classes in order to help his students improve on various sport skills. He wanted a program that could record his students doing sports and then immediately after, the students could analyze the video and make improvements. For example, one of the ideas Mr. Coleman really wanted was a program that could run by itself and record his students swimming and then at the finish line, the video would play for the students.

Another teacher we talked to was the librarian. Although there were no major improvement that we could have made, they wanted a self-checkout system where students can be identified without knowing their id. We could relate to the librarians because having to ask students for their id over and over again can be quite tedious and time-wasting. Our face recognition program was one of the suggestions the librarians came up with and we went with it.

Harry’s scuba diving instructor for his Interim was another teacher we interviewed. The instructor wanted a program that could track breathing patterns so students would know how to effectively breathe. We knew that these kinds of problems is something that is hard for all kinds of physical training teacher, so we could relate. When trying to teach someone a physical technique, its hard to describe the concept and usually you can only resort to technology.

 

Design thinking sentence:

 

List of Equipment:

Webcam (laptop)

Laptop

 

Program:

face detection:

face comparison:

Our program is designed to detect your face and identify the person so checking out in the library will be more convenient for the librarian. Our final end goal wasn’t met since it was way too hard, but we did accomplish part of the project. For the first video, you can see how the face detection works. Using the library OpenCV, we used the function cv2.VideoCapture and redirected all the images to a folder ‘faces’. Firstly, we imported Opencv, sys, and other things we needed. Then, the detection display part was coded, making the video capture only the box that detects the face using the haar cascade program. The program ultimately will take 30 images and put them into a folder for later use. For the second video, it is our image comparison code. For this video, we used a database ‘yalefaces’. The code basically reads the images from the folder, then trains them for use. Then it loops and compares the faces using the LBPH Face recognizer. In the folder, there are different people with different facial expression, because the code will read the expressions and compare them to an image. Then, it will print the similarity.

The whole entire coding process was very hard, since Harry and I spent countless hours trying to find the working OpenCV version and all the libraries needed such as PIL, OpenCV, and LBPH Face Detection. Most of the tutorials and guide out there weren’t compatible with our Pycharm and computer, so we had to combine our research on the code. There were many instances where the error that showed up couldn’t be solved, so we needed another alternative. Mr. Lin had also helped us through the process of finding the appropriate libraries.

 

Testing table:

Item Test outcome Fixed Date
If/else function Pass No 1/19
Variables cv2 module not found sometimes appended cv2 to site-packages folder and it worked. 1/19
OpenCV imwrite and imread function were missing repaired cv2 in terminal 1/19
Function Pass No 1/19
Detection display Pass No 1/19
Conditions Pass No 1/19
Loop There was one time where the webcam only took 21 images No, one time error. 1/19

 

Reference:

http://hanzratech.in/2015/02/03/face-recognition-using-opencv.html

https://realpython.com/blog/python/face-recognition-with-python/

https://cmake.org/cmake/help/v3.0/command/install.html

http://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/

Mr. Lin

 

Code:

#creating database
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
import cv2, numpy, os
haar_file = '/Users/Kewlwasabi/Documents/HKIS/10thgrade/i2p/cvFace/haarcascade_frontalface_default.xml'
datasets = 'datasets'  
sub_data = '/Users/Kewlwasabi/Documents/HKIS/10thgrade/i2p/cvFace/faces' #where pictures will be uploaded to
path = os.path.join(datasets, sub_data)
if not os.path.isdir(path):
    os.mkdir(path)
(width, height) = (130, 100)    # defining the size of images 
face_cascade = cv2.CascadeClassifier(haar_file) #haar cascade function for detecting objects on cam
webcam = cv2.VideoCapture(0) # cv2 webcam function
# The program loops until it has 30 images of the face.
count = 1
while count < 31: 
    (_, im) = webcam.read()
    gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 4)
    for (x,y,w,h) in faces:
        cv2.rectangle(im,(x,y),(x+w,y+h),(255,0,0),2)   #Rectangle for face detection
face = gray[y:y + h, x:x + w]
        face_resize = cv2.resize(face, (width, height))
        cv2.imwrite('%s/%s.png' % (path,count), face_resize)
    count += 1
cv2.imshow('OpenCV', im)
    key = cv2.waitKey(10)
    if key == 27:
        break  #program ends after 30 pictures


 Code 2:
#!/usr/bin/python
# Import the required modules
import cv2, os
import numpy as np
from PIL import Image

# For face detection we will use the Haar Cascade provided by OpenCV.
cascadePath = '/Users/Gold/Desktop/temp/Download/frontalFace10/haarcascade_frontalface_default.xml'
faceCascade = cv2.CascadeClassifier(cascadePath)

# For face recognition we will the the LBPH Face Recognizer
recognizer = cv2.face.createLBPHFaceRecognizer()

def get_images_and_labels(path):
    # Append all the absolute image paths in a list image_paths
    # We will not read the image with the .sad extension in the training set
    # Rather, we will use them to test our accuracy of the training
image_paths = [os.path.join(path, f) for f in os.listdir(path) if not f.endswith('.sad')]
    # images will contains face images
images = []
    # labels will contains the label that is assigned to the image
labels = []
    for image_path in image_paths:
        # Read the image and convert to grayscale
image_pil = Image.open(image_path).convert('L')
        # Convert the image format into numpy array
image = np.array(image_pil, 'uint8')
        # Get the label of the image
nbr = int(os.path.split(image_path)[1].split(".")[0].replace("subject", ""))
        # Detect the face in the image
faces = faceCascade.detectMultiScale(image)
        # If face is detected, append the face to images and the label to labels
for (x, y, w, h) in faces:
            images.append(image[y: y + h, x: x + w])
            labels.append(nbr)
            cv2.imshow("Adding faces to traning set...", image[y: y + h, x: x + w])
            cv2.waitKey(50)
    # return the images list and labels list
return images, labels

# Path to the Yale Dataset
path = '/Users/Gold/Downloads/face_recognizer/yalefaces/'
# Call the get_images_and_labels function and get the face images and the
# corresponding labels
images, labels = get_images_and_labels(path)
cv2.destroyAllWindows()

# Perform the tranining
recognizer.train(images, np.array(labels))


# Append the images with the extension .sad into image_paths
image_paths = [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.sad')]
for image_path in image_paths:
    predict_image_pil = Image.open(image_path).convert('L')
    predict_image = np.array(predict_image_pil, 'uint8')
    faces = faceCascade.detectMultiScale(predict_image)
    for (x, y, w, h) in faces:
        nbr_predicted, conf = recognizer.predict(predict_image[y: y + h, x: x + w])
        nbr_actual = int(os.path.split(image_path)[1].split(".")[0].replace("subject", ""))
        if nbr_actual == nbr_predicted:
            print("{} is Correctly Recognized with confidence {}".format(nbr_actual, conf))
        else:
            print("{} is Incorrect Recognized as {}".format(nbr_actual, nbr_predicted))
        cv2.imshow("Recognizing Face", predict_image[y: y + h, x: x + w])
        cv2.waitKey(1000)

I2p Summative Quiz

 

 

 

Photo on 28-11-16 at 11.09 pm

 

Flowchart

Photo on 28-11-16 at 11.08 pm #2

 

Mindmap

Video

 

Testing table:

 

Item Test outcome Fixed Date
If/else Pass No 28/9
Variables Weird interaction between “Insane” difficulty and scoring Yes, added numberofQuestions variable 28/9
Scoring Pass No 28/9
Function Pass No 28/9
List Pass No 28/9
Conditions Pass No 28/9
Loop An infinite loop when there’s a typo in difficulty select Yes, added “break” and else. 28/9

 

 

References:

http://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list-with-python

https://docs.python.org/2/using/cmdline.html

https://www.tutorialspoint.com/python/python_functions.htm

Code with comments:

import time
userScore = 0
numberofQuestions = 5
userName = ""
vDifficulty = ""
#I import time to use delay function and also declare variables in global so it can be used later
def quizIntro():
    global userName
    userName = input("What is your name? ")
    print("Welcome to the Math Quiz, ",userName,"!")
    variable = 0
while variable < 3:
        vIntro = input("Start or Instructions? ")
        vIntro = vIntro.lower()

        if vIntro == "instructions":
            print("Instructions: ")
            time.sleep(1)
            print("""\nThe following quiz is a multiple choice quiz, with A, B, C, D as options.
Your score will be calculated and shown after the game. Good luck!""")
            input("\nPress enter to go back. ")
            continue
        elif vIntro == "start":
            quizSelect()
            break
        else:
            print("Please choose one of the two options above.")
            continue
# The first function of the quiz, which gives instructions and asks for name
def quizSelect():
    global vDifficulty
    global numberofQuestions
    variable2 = 0
while variable2 < 10:
        print("\nSelect your difficulty, Easy, Hard, or Insane.")
        vDifficulty = input("Difficulty: ")
        vDifficulty = vDifficulty.lower()
        if vDifficulty == "easy":
            numberofQuestions = 10
quizEasy()
            break
        elif vDifficulty == "hard":
            numberofQuestions = 10
quizHard()
            break
        elif vDifficulty == "insane":
            numberofQuestions = 5
quizInsane()
        else:
            print("Please select a valid difficulty.")
        continue
#Difficulty selection using if/else and while loop to prevent errors. vDifficulty is called from global. Sets number of questions for later use
def quizEasy():   #10 easy questions using if/else function to tally up score
print("\nQuestion 1: What is 1 + 2?")
    time.sleep(1)
    print("A: 4")
    print("B: 5")
    print("C: 3")
    print("D: 6")
    vAnswer = input("Answer: ")
    vAnswer = vAnswer.upper()
    if vAnswer == "C":
        print("Correct!")
        global userScore
        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 2: What is 3 x 5?")
    time.sleep(1)
    print("A: 24")
    print("B: 12")
    print("C: 10")
    print("D: 15")
    vAnswer2 = input("Answer: ")
    vAnswer2 = vAnswer2.upper()
    if vAnswer2 == "D":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 3: What is 8 - 3?")
    time.sleep(1)
    print("A: 5")
    print("B: 10")
    print("C: 8")
    print("D: 0")
    vAnswer3 = input("Answer: ")
    vAnswer3 = vAnswer3.upper()
    if vAnswer3 == "A":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 4: What is 9 + 10?")
    time.sleep(1)
    print("A: 21")
    print("B: 19")
    print("C: 20")
    print("D: 15")
    vAnswer4 = input("Answer: ")
    vAnswer4 = vAnswer4.upper()
    if vAnswer4 == "B":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 5: What is 16 - 9?")
    time.sleep(1)
    print("A: 7")
    print("B: 8")
    print("C: 10")
    print("D: 5")
    vAnswer5 = input("Answer: ")
    vAnswer5 = vAnswer5.upper()
    if vAnswer5 == "A":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 6: What is 7 x 8?")
    time.sleep(1)
    print("A: 54")
    print("B: 63")
    print("C: 56")
    print("D: 49")
    vAnswer6 = input("Answer: ")
    vAnswer6 = vAnswer6.upper()
    if vAnswer6 == "C":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 7: What is 15 / 3?")
    time.sleep(1)
    print("A: 3")
    print("B: 10")
    print("C: 5")
    print("D: 2")
    vAnswer7 = input("Answer: ")
    vAnswer7 = vAnswer7.upper()
    if vAnswer7 == "C":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 8: What is 20 / 4")
    time.sleep(1)
    print("A: 3")
    print("B: 5")
    print("C: 10")
    print("D: 2")
    vAnswer8 = input("Answer: ")
    vAnswer8 = vAnswer8.upper()
    if vAnswer8 == "B":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 9: What is 18 + 5?")
    time.sleep(1)
    print("A: 27")
    print("B: 20")
    print("C: 33")
    print("D: 23")
    vAnswer9 = input("Answer: ")
    vAnswer9 = vAnswer9.upper()
    if vAnswer9 == "D":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 10: What is 12 x 12?")
    time.sleep(1)
    print("A: 132")
    print("B: 144")
    print("C: 100")
    print("D: 155")
    vAnswer10 = input("Answer: ")
    vAnswer10 = vAnswer10.upper()
    if vAnswer10 == "B":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
        quizScore()
    else:
        print("Incorrect!")
        time.sleep(1)
        quizScore()

def quizHard(): #10 hard questions using if/else and also tallies up score.
print("\nQuestion 1: 3 + x = 7. What is x?")
    time.sleep(1)
    print("A: 4")
    print("B: 5")
    print("C: 1")
    print("D: 0")
    vAnswer = input("Answer: ")
    vAnswer = vAnswer.upper()
    if vAnswer == "A":
        print("Correct!")
        global userScore
        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 2: 9x + 1 = 10. What is x?")
    time.sleep(1)
    print("A: 9")
    print("B: 1")
    print("C: 0")
    print("D: 0.6")
    vAnswer2 = input("Answer: ")
    vAnswer2 = vAnswer2.upper()
    if vAnswer2 == "B":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 3: x/2 = 4. What is x?")
    time.sleep(1)
    print("A: 8")
    print("B: 1")
    print("C: 0")
    print("D: 2")
    vAnswer3 = input("Answer: ")
    vAnswer3 = vAnswer3.upper()
    if vAnswer3 == "A":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 4: 4x - 6 = 10. What is x?")
    time.sleep(1)
    print("A: Mexico")
    print("B: 2")
    print("C: 7")
    print("D: 4")
    vAnswer4 = input("Answer: ")
    vAnswer4 = vAnswer4.upper()
    if vAnswer4 == "D":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 5: 2x/3 = 8. What is x?")
    time.sleep(1)
    print("A: 6")
    print("B: 24")
    print("C: 12")
    print("D: 16")
    vAnswer5 = input("Answer: ")
    vAnswer5 = vAnswer5.upper()
    if vAnswer5 == "C":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 6: 6x + 3 = 21. What is 2 + 5?")
    time.sleep(1)
    print("A: 3")
    print("B: 7")
    print("C: 9")
    print("D: 10")
    vAnswer6 = input("Answer: ")
    vAnswer6 = vAnswer6.upper()
    if vAnswer6 == "B":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 7: 8/x = 2. What is x?")
    time.sleep(1)
    print("A: 4")
    print("B: 8")
    print("C: 2")
    print("D: 1")
    vAnswer7 = input("Answer: ")
    vAnswer7 = vAnswer7.upper()
    if vAnswer7 == "A":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 8: (x+3)/4 = 4. What is x?")
    time.sleep(1)
    print("A: 4")
    print("B: 16")
    print("C: 8")
    print("D: 13")
    vAnswer8 = input("Answer: ")
    vAnswer8 = vAnswer8.upper()
    if vAnswer8 == "D":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 9: (3/6)x = 0. What is x?")
    time.sleep(1)
    print("A: 1")
    print("B: 0.5")
    print("C: 0")
    print("D: 6")
    vAnswer9 = input("Answer: ")
    vAnswer9 = vAnswer9.upper()
    if vAnswer9 == "C":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
    else:
        print("Incorrect!")
        time.sleep(1)
    print("\nQuestion 10: You see rich man Rungee walking towards you. Do you...")
    time.sleep(1)
    print("A: Donate")
    print("B: Greet him")
    print("C: Return the envelope")
    print("D: Run")
    vAnswer10 = input("Answer: ")
    vAnswer10 = vAnswer10.upper()
    if vAnswer10 == "A":
        print("Correct!")

        userScore = userScore + 1
time.sleep(1)
        quizScore()
    else:
        print("Incorrect!")
        time.sleep(1)
        quizScore()

def quizInsane(): #5 insane questions that you are meant to get wrong
print("\nWhat is the first letter of the alphabet?")
    time.sleep(1)
    print("A: B")
    print("B: C")
    print("C: D")
    print("D: A")
    vAnswer = input("Answer: ")
    vAnswer = vAnswer.upper()
    if vAnswer == "A":
        print("B is the second letter of the alphabet...")
        time.sleep(1)
    elif vAnswer == "D":
        print("D is the fourth letter of the alphabet...")
    else:
        print("Incorrect!")
        time.sleep(1)

    print("\nQuestion 2: What is the capital of Spain?")
    time.sleep(1)
    print("A: Venezuela")
    print("B: Rochester")
    print("C: Huntingtons")
    print("D: Mexico")
    vAnswer2 = input("Answer: ")
    vAnswer2 = vAnswer2.upper()
    print("Incorrect! The answer is Madrid.")
    time.sleep(1)

    print("\nIn the picture above, what is the object next to the vase?")
    time.sleep(1)
    print("A: Apple")
    print("B: Orb")
    print("C: Egg")
    print("D: Pear")
    vAnswer3 = input("Answer: ")
    vAnswer3 = vAnswer3.upper()
    print("Incorrect! 1 + 1 is 2.")
    time.sleep(1)

    print("\nWhich gaming platform is the best below?")
    time.sleep(1)
    print("A: PC")
    print("B: Xbox")
    print("C: Playstation")
    print("D: Gameboy")
    vAnswer4 = input("Answer: ")
    vAnswer4 = vAnswer4.upper()
    if vAnswer4 == "A":
        print("Incorrect! The Xbox is vastly better in all aspects.")
    elif vAnswer4 == "B":
        print("Incorrect! Get a PC you console peasant.")
    else:
        print("Incorrect!")
        time.sleep(1)


    print("\nWho is Albert Einstein")
    time.sleep(1)
    print("A: A scientist")
    print("B: A scientific researcher")
    print("C: A person who indulges in science")
    print("D: A person who studies in the field of science")
    vAnswer5 = input("Answer: ")
    vAnswer5 = vAnswer5.upper()
    print("Incorrect! Albert Eistein is a scientist. ")
    quizScore()

def quizScore(): #Final function, calls name and difficulty variable from global and calculates score. Then prints a comment based on score.
print ("\nYour name: ",userName)
    global vDifficulty
    vDifficulty = vDifficulty.capitalize()
    print ("Difficulty: ",vDifficulty)
    print("On this test, you've score a total of ",userScore, "/",numberofQuestions)
    if userScore < 5:
        print("You failed!")
    elif userScore >= 5 and userScore < 10:
        print("You did ok.")
    else:
        print("Full score!")
    time.sleep(3)
    input("\nPress enter to play again.")   #After playing again, it redirects you to difficulty selection, skipping intro.
quizSelect()





quizIntro()    #Calling the first function

 

 

 

Quiz Summative Progress 2

This class, I fixed the difficulty bug and also tried to make my questions into a textfile. I typed up the questions and tried to put it in my code, but there was a weird glitch that printed the line of code instead of the actual textfile. For next class, I’m going to try the textfile again, and also test all possible outcomes of my code, so there isn’t any bugs. There was also a repeating glitch I need to fix, which would print a line indefinitely when I made a typo.

Python Summative Progress

This class, I finished up the scoring system and also finished the questions. The code works fine but there are some bugs in the code which I need to fix. The scoring system I used was first, setting a variable “userScore”. I set the variable globally so I could call it in a function. Then, I made it so for every question answered correctly, the score would +1. At the end, I would print the user’s name, difficulty, and score. The difficulty print is still bugged since it doesn’t print it if I chose hard difficulty, something I need to fix. For next time, I’ll polish up my code and fix other mistakes.

www.github.com/kewlwasabi/l2p

Python Lesson 3

Today we learned about pseudo code and flow charts. The main purpose of this was to understand how to use functions such as for, while, and, or. Those were called pseudo code since they did exactly what they sounded like. Another thing we did was flow charts. This helped us understand how to code something using loops. If, elif, and else were things we used when setting a specific set of conditions. If the input didn’t satisfy a certain condition, the code would move onto the next condition. If that doesn’t work too, it will carry out the else command. We used the knowledge we learned and made a guessing game. We had the while loop so the code will allow us to guess again after a failed attempt. Then at the end, we had break which stopped the code after the last condition was met. Screen Shot 2016-10-18 at 1.24.21 pm