diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..e14b054 Binary files /dev/null and b/.DS_Store differ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1c28e71 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python +python: + - "3.9" + - "3.5" + - "3.10" +# command to run tests +script: + - python TestModule1.py diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..05eec4a --- /dev/null +++ b/Readme.md @@ -0,0 +1,60 @@ +# Function details and how they work + +## Motivation +We want to create a quiz apps for the authoized student to test their understanding on the material before taking the actual exam. This application will ask user for the subject(Data533, Data541, Data530) and difficulty (easy, normal, hard, all(default)) that they want to be quized on. And validated their answer by giving feedback to them after every question. Finally the quiz apps will calculate a total marks after finishing all the question in order for them to keep track on their understanding on a specific topic. The application also allows teacher to access the quiz to see what question is the student being ask and for error checking purpose. +## Package1 +This package will include the personal information input,output and checking. Also, we will divide it into two categories, student and teacher. +### Module 1 +In Module 1, we will set functions about **information-input**, such as name, ID. If a student, users need to input their major and degree; if a teacher, users need to input their research direction and teaching length. +- def group(): +- def name(): +- def ID(): +- def major(): +- def research(): +### Module 2 +In Module 2, we will set functions about **information-output**, we use the **inheritance** in this module. The Group will show the common information: name and ID. Inside the Group, there are Student (show additional information about major and degree) and Teacher (show additional information about research and length) +- class Group: +- class Student(Group): +- class Teacher(Group): +### Module 3 +Checking whether student or teacher is in the list, according to their ID, and checking whether the input of name is empty. +**Tips:As a testing example, now we only include two ID in the list,"12345" and "54321"** +- def __init__(self): +- def check_inlist(self, input): +- def check_IsNull(self): + + +## Package2 +This sub-package is all about processing question database and contain all the necessary checking function for the question and answer when user input in the quiz apps. This Sub-Package include 3 Module, **Checking**(the brain of the quiz apps), **Question**(for processing database question) and **Course**(appending defaulty to the database question) +### Module 1 +This Module contain ```class Checking: ```, which is the brain of the quizzing apps, it contain all the necessary checking function such as: +- isEmpty(self) - checking if there is more question to the question set. If there is, run function next_question() to prompt the user with new question and ask for their input. +- next_question(self) - prompt the user with new question and ask for their input and validate user answer using check_answer(). +- check_answer(self, user_answer, correct_answer) - checking if the user input matched the database answer and if not prompt the user with the correct anser. +- check_score(self) - checking user score. + +### Module 2 +This Module contain ```class Question(Checking):```,which is inherited from Checking class, this class only have one function: +- __init__ (self, q_text, q_answer, q_diff) - process database’s question and allocate them into question, anser and difficulty. + + +### Module 3 +This Module contain ```Course(Question,Checking):``` which is inherited from Checking class and Question class, this module are for appending database’s questions, answer into separate array with different difficulty for the other class to access based on user inputs in the future. this class only have 4 function: +- append_text(self,question) - for appending database’s question in to its own question array +- append_answer(self,question) - for appending database’s answer in to its own answer array +- append_difficulty(self,question) - for appending database’s difficultyin to its own difficulty array +- append_courseq(self) - for appending database’s question, answer according to the difficulty into 4 different question set array for user to access it after knowing the user difficulty that he/she want to be quiz on. + + + + + + + + + + + + + + diff --git a/main.ipynb b/main.ipynb new file mode 100644 index 0000000..dd2a5a6 --- /dev/null +++ b/main.ipynb @@ -0,0 +1,276 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a7a1bade-15c1-4c1a-ab02-f83741cb7a71", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " __ __ _____ ______ ______ __ __ __ ______ ______ ______ ______ ______ \n", + " /\\ \"-./ \\ /\\ __-. /\\ ___\\ /\\ __ \\ /\\ \\/\\ \\ /\\ \\ /\\___ \\ /\\ __ \\ /\\ == \\ /\\ == \\ /\\ ___\\ \n", + " \\ \\ \\-./\\ \\ \\ \\ \\/\\ \\ \\ \\___ \\ \\ \\ \\/\\_\\ \\ \\ \\_\\ \\ \\ \\ \\ \\/_/ /__ \\ \\ __ \\ \\ \\ _-/ \\ \\ _-/ \\ \\___ \\ \n", + " \\ \\_\\ \\ \\_\\ \\ \\____- \\/\\_____\\ \\ \\___\\_\\ \\ \\_____\\ \\ \\_\\ /\\_____\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_\\ \\/\\_____\\ \n", + " \\/_/ \\/_/ \\/____/ \\/_____/ \\/___/_/ \\/_____/ \\/_/ \\/_____/ \\/_/\\/_/ \\/_/ \\/_/ \\/_____/ \n", + "\n", + "\n" + ] + } + ], + "source": [ + "data533_q= []\n", + "data541_q= []\n", + "\n", + "from pkg.pkg1 import information_input as ii\n", + "from pkg.pkg1 import information_output as io \n", + "from pkg.pkg1 import information_check as ic\n", + "from pkg.pkg2 import Course as co\n", + "from pkg.pkg2 import Question as qu\n", + "\n", + "v1 = \" \"\n", + "v2 = \" \"\n", + "exit = \"n\"\n", + "courselist = [\"data533\",\"data541\",\"data530\"]\n", + "\n", + "\n", + "print(''' __ __ _____ ______ ______ __ __ __ ______ ______ ______ ______ ______ ''')\n", + "print(''' /\\ \"-./ \\ /\\ __-. /\\ ___\\ /\\ __ \\ /\\ \\/\\ \\ /\\ \\ /\\___ \\ /\\ __ \\ /\\ == \\ /\\ == \\ /\\ ___\\ ''')\n", + "print(''' \\ \\ \\-./\\ \\ \\ \\ \\/\\ \\ \\ \\___ \\ \\ \\ \\/\\_\\ \\ \\ \\_\\ \\ \\ \\ \\ \\/_/ /__ \\ \\ __ \\ \\ \\ _-/ \\ \\ _-/ \\ \\___ \\ ''')\n", + "print(''' \\ \\_\\ \\ \\_\\ \\ \\____- \\/\\_____\\ \\ \\___\\_\\ \\ \\_____\\ \\ \\_\\ /\\_____\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_\\ \\/\\_____\\ ''')\n", + "print(''' \\/_/ \\/_/ \\/____/ \\/_____/ \\/___/_/ \\/_____/ \\/_/ \\/_____/ \\/_/\\/_/ \\/_/ \\/_/ \\/_____/ ''')\n", + "\n", + "print(\"\\n\")\n", + "\n", + "while True:\n", + " if exit.lower() == 'y':\n", + " break\n", + " usr = input(\"Are you are Student or Teacher? \")\n", + " if usr.lower() == 'teacher':\n", + " print(\"****************************************************************************************************************************\")\n", + " print(\"*************************************************** Logged in as Teacher ***************************************************\")\n", + " print(\"****************************************************************************************************************************\")\n", + " inlist = False\n", + " while inlist == False:\n", + " if v1 == \" \":\n", + " name = ii.name()\n", + " iid = ii.ID()\n", + " research = ii.research()\n", + " length = ii.length()\n", + " temp1 = ic.Info_Check(name,iid)\n", + " if temp1.check_IsNull() == False:\n", + " if temp1.check_inlist() == True:\n", + " v1 = io.Teacher(name, iid, research, length);\n", + " groups= [v1]\n", + " print(\"\\n################################\")\n", + " for group in groups:\n", + " group.display()\n", + " inlist == True\n", + " print(\"################################\\n\")\n", + " break\n", + " else:\n", + " print(\"\\n########################################## User Not In List, Please Enter Again ##########################################\\n\")\n", + " else:\n", + " print(\"\\n######################################## User Name Empty, Please Enter Name Again ########################################\\n\")\n", + " else:\n", + " pass\n", + " else:\n", + " print(\"****************************************************************************************************************************\")\n", + " print(\"*************************************************** Logged in as Student ***************************************************\")\n", + " print(\"****************************************************************************************************************************\")\n", + " inlist = False\n", + " while inlist == False:\n", + " if v2 == \" \":\n", + " name = ii.name()\n", + " iid = ii.ID()\n", + " major = ii.major()\n", + " degree = ii.degree()\n", + " temp1 = ic.Info_Check(name,iid)\n", + " if temp1.check_IsNull() == False:\n", + " if temp1.check_inlist() == True:\n", + " v2 = io.Student(name, iid, major,degree);\n", + " groups= [v2]\n", + " print(\"\\n################################\")\n", + " for group in groups:\n", + " group.display()\n", + " inlist == True\n", + " print(\"################################\\n\")\n", + " break\n", + "\n", + " else:\n", + " print(\"\\n########################################## User Not In List, Please Enter Again ##########################################\\n\")\n", + " else:\n", + " print(\"\\n######################################## User Name Empty, Please Enter Name Again ########################################\\n\")\n", + " else:\n", + " pass\n", + "\n", + " \n", + " while True: \n", + " usr_input = input(\"What Subject Question Set Would You like to Access? \")\n", + " if usr_input != '' and usr_input.lower() in courselist:\n", + " input_diff = input(\"Difficulty(easy, hard, normal): \")\n", + " if usr_input.lower() == \"data533\":\n", + " data533 = co.Course([\n", + " { \n", + " \"question\": \"Which of the following represents a template or blueprint that defines objects of the same type?(Answer in Letter) \\nA) A class \\nB) An object \\nC) A method \\nD) An attribute \\nE) None of the above\\n\",\n", + " \"correct_answer\": \"A\",\n", + " \"difficulty\": \"easy\"\n", + " },\n", + " {\n", + " \"question\": \"How many of the following statements are TRUE?(Answer in Letter) \\n1) Class attributes owned by the class as a whole \\n2) Class attributes are shared among all objects of that class \\n3) Class attributes are good for building counter of how many instances of the class have been made \\n4) Each instance has its own value for class attribute \\n\",\n", + " \"correct_answer\": \"3\",\n", + " \"difficulty\": \"hard\"\n", + " }\n", + " ],\n", + " input_diff,usr.lower())\n", + "\n", + " print(\"****************************************************************************************************************************\")\n", + " print(\"*************************************** Welcome to DATA533. *****************************************\")\n", + " print(\"*************************** There is \" + str(data533.NumInQSet) + \" questions in total in DATA533. **************************\")\n", + " print(\"****************************************************************************************************************************\")\n", + " while data533.isEmpty():\n", + " data533.next_question()\n", + "\n", + " data533.check_score()\n", + " exit = input(\"exit? (Y/N)\")\n", + " \n", + " if exit.lower() == 'y':\n", + " break\n", + " else: \n", + " continue\n", + "\n", + "\n", + " elif usr_input.lower() == \"data541\":\n", + " data541 = co.Course([\n", + " {\n", + " \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\n", + " \"correct_answer\": \"3\",\n", + " \"difficulty\": \"easy\"\n", + " },\n", + " {\n", + " \"question\": \"Which of the following command creates a copy of a remote repository to your local machine.(Answer in Letter) \\n A) git add \\n B) git commit \\n C) git clone \\n D) git pull\\n E) git push \\n\",\n", + " \"correct_answer\": \"c\",\n", + " \"difficulty\": \"normal\"\n", + " },\n", + " {\n", + " \"question\": \" How many of the following statements are TRUE?(Answer in Number) \\n1) git branch NewBranch creates a new branch \\n2) git branch NewBranch does not check out to the NewBranch \\n3) git branch is tightly integrated with the git checkout and git merge commands \\n4) git branch -d NewBranch can be used to force delete the branch called NewBranch\\n\",\n", + " \"correct_answer\": \"3\",\n", + " \"difficulty\": \"easy\"\n", + " }\n", + " ],\n", + "\n", + " input_diff,usr.lower())\n", + "\n", + "\n", + " print(\"****************************************************************************************************************************\")\n", + " print(\"*************************************** Welcome to DATA541. *****************************************\")\n", + " print(\"*************************** There is \" + str(data541.NumInQSet) + \" questions in total in DATA541. **************************\")\n", + " print(\"****************************************************************************************************************************\")\n", + " while data541.isEmpty():\n", + " data541.next_question()\n", + "\n", + " data541.check_score()\n", + " exit = input(\"exit? (Y/N)\")\n", + " \n", + " if exit.lower() == 'y':\n", + " break\n", + " else: \n", + " continue\n", + " \n", + " elif usr_input.lower() == \"data530\":\n", + " data530 = co.Course([\n", + " {\n", + " \"question\": \" Is a cell phone a computer? \\nA) yes \\nB) no\\n \",\n", + " \"correct_answer\": \"a\",\n", + " \"difficulty\": \"easy\"\n", + " },\n", + " {\n", + " \"question\": \"Does a hard drive store data permanently? \\nA) yes \\nB) no\\n\",\n", + " \"correct_answer\": \"a\",\n", + " \"difficulty\": \"normal\"\n", + " },\n", + " {\n", + " \"question\": \"What ASCII character is 0100 0100?\\nA) A\\nB) !\\nC) @ \\nD) D\\n\",\n", + " \"correct_answer\": \"d\",\n", + " \"difficulty\": \"hard\"\n", + " },\n", + " {\n", + " \"question\": \" Which is bigger?\\nA) 10 TB\\nB) 100 GB\\nC) 1,000,000,000,000 bytes\\nD) 1 PB\",\n", + " \"correct_answer\": \"d\",\n", + " \"difficulty\": \"normal\"\n", + " }\n", + " ],\n", + "\n", + " input_diff,usr.lower())\n", + "\n", + "\n", + " print(\"****************************************************************************************************************************\")\n", + " print(\"*************************************** Welcome to DATA530. *****************************************\")\n", + " print(\"*************************** There is \" + str(data530.NumInQSet) + \" questions in total in DATA530. **************************\")\n", + " print(\"****************************************************************************************************************************\")\n", + " while data530.isEmpty():\n", + " data530.next_question()\n", + "\n", + " data530.check_score()\n", + " exit = input(\"exit? (Y/N)\")\n", + " \n", + " if exit.lower() == 'y':\n", + " break\n", + " else: \n", + " continue\n", + " \n", + " break\n", + " \n", + " else:\n", + " print('User input is empty or the course in not in the list. Please Enter the course number again.')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d95b57e-bc97-4afc-9a4b-bfae7b2a27f3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc5d16bd-e176-4372-baa9-b46b45ad0901", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e680011c-9701-4d19-a1ab-c53ab98a1a33", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/pkg/.DS_Store b/pkg/.DS_Store new file mode 100644 index 0000000..70a2d43 Binary files /dev/null and b/pkg/.DS_Store differ diff --git a/pkg/pkg1/.DS_Store b/pkg/pkg1/.DS_Store new file mode 100644 index 0000000..7eb5351 Binary files /dev/null and b/pkg/pkg1/.DS_Store differ diff --git a/pkg/pkg1/.ipynb_checkpoints/information_check-checkpoint.py b/pkg/pkg1/.ipynb_checkpoints/information_check-checkpoint.py new file mode 100644 index 0000000..589bdf9 --- /dev/null +++ b/pkg/pkg1/.ipynb_checkpoints/information_check-checkpoint.py @@ -0,0 +1,21 @@ +class Info_Check(): + + def __init__(self,name,iid): + self.list = ["12345","54321"] + self.name = name + self.iid = iid + + def check_inlist(self): + if self.iid.lower() in self.list: + return True + else: + return False + + def check_IsNull(self): + if self.name=="": + return True + else: + return False + + + \ No newline at end of file diff --git a/pkg/pkg1/.ipynb_checkpoints/information_input-checkpoint.py b/pkg/pkg1/.ipynb_checkpoints/information_input-checkpoint.py new file mode 100644 index 0000000..6e1bc39 --- /dev/null +++ b/pkg/pkg1/.ipynb_checkpoints/information_input-checkpoint.py @@ -0,0 +1,27 @@ +def group(): + g=input("Are you a student or a teacher?") + return g + +def name(): + n=input("What's your name?") + return n + +def ID(): + I=input("What's your ID? ") + return I + +# a student +def major(): + n=input("What's your major?(optional)") + return n +def degree(): + n=input("Are you an undergraduate or postgraduate?(optional)") + return n +# a teacher +def research(): + n=input("what is your research direction?(optional)") + return n + +def length(): + n=input("How many years since be a tearcher?(optional)") + return n \ No newline at end of file diff --git a/pkg/pkg1/.ipynb_checkpoints/information_output-checkpoint.py b/pkg/pkg1/.ipynb_checkpoints/information_output-checkpoint.py new file mode 100644 index 0000000..591eece --- /dev/null +++ b/pkg/pkg1/.ipynb_checkpoints/information_output-checkpoint.py @@ -0,0 +1,28 @@ +class Group: + def __init__(self, name, ID): + self.name = name + self.ID = ID + + def display(self): + print('Name:{} ID:{} '.format(self.name, self.ID)) + + +class Student(Group): + def __init__(self, name, ID, major, degree): + Group.__init__(self, name, ID) + self.major=major + self.degree=degree + + def display(self): + Group.display(self) + print('Major: {} Degree: {}'.format(self.major, self.degree)) + +class Teacher(Group): + def __init__(self, name, ID, research, length): + Group.__init__(self, name, ID) + self.research=research + self.length=length + + def display(self): + Group.display(self) + print('Research: {} Length: {}'.format(self.research, self.length)) \ No newline at end of file diff --git a/pkg/pkg1/__pycache__/information_check.cpython-39.pyc b/pkg/pkg1/__pycache__/information_check.cpython-39.pyc new file mode 100644 index 0000000..311c275 Binary files /dev/null and b/pkg/pkg1/__pycache__/information_check.cpython-39.pyc differ diff --git a/pkg/pkg1/__pycache__/information_input.cpython-39.pyc b/pkg/pkg1/__pycache__/information_input.cpython-39.pyc new file mode 100644 index 0000000..fb97e2d Binary files /dev/null and b/pkg/pkg1/__pycache__/information_input.cpython-39.pyc differ diff --git a/pkg/pkg1/__pycache__/information_output.cpython-39.pyc b/pkg/pkg1/__pycache__/information_output.cpython-39.pyc new file mode 100644 index 0000000..c9bafbc Binary files /dev/null and b/pkg/pkg1/__pycache__/information_output.cpython-39.pyc differ diff --git a/pkg/pkg1/information_check.py b/pkg/pkg1/information_check.py new file mode 100644 index 0000000..589bdf9 --- /dev/null +++ b/pkg/pkg1/information_check.py @@ -0,0 +1,21 @@ +class Info_Check(): + + def __init__(self,name,iid): + self.list = ["12345","54321"] + self.name = name + self.iid = iid + + def check_inlist(self): + if self.iid.lower() in self.list: + return True + else: + return False + + def check_IsNull(self): + if self.name=="": + return True + else: + return False + + + \ No newline at end of file diff --git a/pkg/pkg1/information_input.py b/pkg/pkg1/information_input.py new file mode 100644 index 0000000..8e46308 --- /dev/null +++ b/pkg/pkg1/information_input.py @@ -0,0 +1,29 @@ +def group(): + g=input("Are you a student or a teacher?") + return g + +def name(): + n=input("What's your name?") + return n + +def ID(): + I=input("What's your ID? ") + return I + +# a student +def major(): + n=input("What's your major?(optional)") + return n +def degree(): + n=input("Are you an undergraduate or postgraduate?(optional)") + return n +# a teacher +def research(): + n=input("what is your research direction?(optional)") + return n + +def length(): + n=input("How many years since be a tearcher?(optional)") + return n + +try diff --git a/pkg/pkg1/information_output.py b/pkg/pkg1/information_output.py new file mode 100644 index 0000000..591eece --- /dev/null +++ b/pkg/pkg1/information_output.py @@ -0,0 +1,28 @@ +class Group: + def __init__(self, name, ID): + self.name = name + self.ID = ID + + def display(self): + print('Name:{} ID:{} '.format(self.name, self.ID)) + + +class Student(Group): + def __init__(self, name, ID, major, degree): + Group.__init__(self, name, ID) + self.major=major + self.degree=degree + + def display(self): + Group.display(self) + print('Major: {} Degree: {}'.format(self.major, self.degree)) + +class Teacher(Group): + def __init__(self, name, ID, research, length): + Group.__init__(self, name, ID) + self.research=research + self.length=length + + def display(self): + Group.display(self) + print('Research: {} Length: {}'.format(self.research, self.length)) \ No newline at end of file diff --git a/pkg/pkg2/.ipynb_checkpoints/Course-checkpoint.py b/pkg/pkg2/.ipynb_checkpoints/Course-checkpoint.py new file mode 100644 index 0000000..113f378 --- /dev/null +++ b/pkg/pkg2/.ipynb_checkpoints/Course-checkpoint.py @@ -0,0 +1,56 @@ +from pkg.pkg2 import Question as Q +from pkg.pkg2 import Checking as C + +class Course(Q.Question,C.Checking): + def __init__(self,question_data,input_diff,usr): + self.course_q = [] + self.ez_course_q = [] + self.hard_course_q = [] + self.normal_course_q = [] + self.question_data = question_data + self.inputdiff = input_diff + self.usr = usr + self.append_courseq() + + if self.inputdiff == "easy": + C.Checking.__init__(self,self.ez_course_q,self.usr) + elif self.inputdiff == "normal": + C.Checking.__init__(self,self.normal_course_q,self.usr) + elif self.inputdiff == "hard": + C.Checking.__init__(self,self.hard_course_q,self.usr) + else: + C.Checking.__init__(self,self.course_q,self.usr) + + + def append_text(self,question): + self.question_text = question["question"] + return question["question"] + + def append_answer(self,question): + self.question_answer = question["correct_answer"] + return question["correct_answer"] + + def append_difficulty(self,question): + self.question_difficulty = question["difficulty"] + return question["difficulty"] + + + def append_courseq(self): + for question in self.question_data: + self.append_text(question) + self.append_answer(question) + self.append_difficulty(question) + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + + self.course_q.append(new_question) + + if self.question_difficulty == "easy": + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + self.ez_course_q.append(new_question) + elif self.question_difficulty == "normal": + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + self.normal_course_q.append(new_question) + elif self.question_difficulty == "hard": + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + self.hard_course_q.append(new_question) + \ No newline at end of file diff --git a/pkg/pkg2/.ipynb_checkpoints/Question-checkpoint.py b/pkg/pkg2/.ipynb_checkpoints/Question-checkpoint.py new file mode 100644 index 0000000..3148af1 --- /dev/null +++ b/pkg/pkg2/.ipynb_checkpoints/Question-checkpoint.py @@ -0,0 +1,8 @@ +from pkg.pkg2 import Checking as C + +class Question(C.Checking): + def __init__(self, q_text, q_answer, q_diff): + self.text = q_text + self.answer = q_answer + self.diff = q_diff + \ No newline at end of file diff --git a/pkg/pkg2/Checking.py b/pkg/pkg2/Checking.py new file mode 100644 index 0000000..e0633bd --- /dev/null +++ b/pkg/pkg2/Checking.py @@ -0,0 +1,52 @@ +class Checking: + + def __init__(self, questions, usr): + self.quesBank = questions + self.usr = usr + # self.usr_input = usr_input + self.NumInQSet = len(questions) + self.quesNum = 0 + self.score = 0 + self.ez_course_q = [] + self.hard_course_q = [] + self.normal_course_q = [] + + def next_question(self): + current_question = self.quesBank[self.quesNum] + + self.quesNum += 1 + if self.usr == 'teacher': + print("Question " + str(self.quesNum)+ ". " + str(current_question.text)) + self.check_answer(current_question.answer, current_question.answer) + else: + usr_input = input("Question " + str(self.quesNum)+ ". " + str(current_question.text)) + self.check_answer(usr_input.lower(), current_question.answer) + + def isEmpty(self): + return self.quesNum < len(self.quesBank) + + def check_answer(self, user_answer, correct_answer): + + if user_answer.lower() == correct_answer: + if self.usr == 'teacher': + self.score += 1 + print("Correct answer is: " + str(correct_answer)+ "\n") + return(True) + + else: + self.score += 1 + print("Correct!!! \n \n \n") + return(True) + + else: + print("Wrong :( \n \n \n") + print("The correct answer is: " + str(correct_answer)+ "\n") + return(False) + + def check_score(self): + print("**************************************** ") + print("**************************************** \n") + print("Final score: " + str(self.score) + " out of " + str(self.quesNum) + ". \n") + print("**************************************** ") + print("**************************************** \n") + \ No newline at end of file diff --git a/pkg/pkg2/Course.py b/pkg/pkg2/Course.py new file mode 100644 index 0000000..113f378 --- /dev/null +++ b/pkg/pkg2/Course.py @@ -0,0 +1,56 @@ +from pkg.pkg2 import Question as Q +from pkg.pkg2 import Checking as C + +class Course(Q.Question,C.Checking): + def __init__(self,question_data,input_diff,usr): + self.course_q = [] + self.ez_course_q = [] + self.hard_course_q = [] + self.normal_course_q = [] + self.question_data = question_data + self.inputdiff = input_diff + self.usr = usr + self.append_courseq() + + if self.inputdiff == "easy": + C.Checking.__init__(self,self.ez_course_q,self.usr) + elif self.inputdiff == "normal": + C.Checking.__init__(self,self.normal_course_q,self.usr) + elif self.inputdiff == "hard": + C.Checking.__init__(self,self.hard_course_q,self.usr) + else: + C.Checking.__init__(self,self.course_q,self.usr) + + + def append_text(self,question): + self.question_text = question["question"] + return question["question"] + + def append_answer(self,question): + self.question_answer = question["correct_answer"] + return question["correct_answer"] + + def append_difficulty(self,question): + self.question_difficulty = question["difficulty"] + return question["difficulty"] + + + def append_courseq(self): + for question in self.question_data: + self.append_text(question) + self.append_answer(question) + self.append_difficulty(question) + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + + self.course_q.append(new_question) + + if self.question_difficulty == "easy": + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + self.ez_course_q.append(new_question) + elif self.question_difficulty == "normal": + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + self.normal_course_q.append(new_question) + elif self.question_difficulty == "hard": + new_question = Q.Question(self.question_text, self.question_answer,self.question_difficulty) + self.hard_course_q.append(new_question) + \ No newline at end of file diff --git a/pkg/pkg2/Question.py b/pkg/pkg2/Question.py new file mode 100644 index 0000000..3148af1 --- /dev/null +++ b/pkg/pkg2/Question.py @@ -0,0 +1,8 @@ +from pkg.pkg2 import Checking as C + +class Question(C.Checking): + def __init__(self, q_text, q_answer, q_diff): + self.text = q_text + self.answer = q_answer + self.diff = q_diff + \ No newline at end of file diff --git a/pkg/pkg2/__pycache__/Checking.cpython-39.pyc b/pkg/pkg2/__pycache__/Checking.cpython-39.pyc new file mode 100644 index 0000000..e42cf79 Binary files /dev/null and b/pkg/pkg2/__pycache__/Checking.cpython-39.pyc differ diff --git a/pkg/pkg2/__pycache__/Course.cpython-39.pyc b/pkg/pkg2/__pycache__/Course.cpython-39.pyc new file mode 100644 index 0000000..c46de97 Binary files /dev/null and b/pkg/pkg2/__pycache__/Course.cpython-39.pyc differ diff --git a/pkg/pkg2/__pycache__/Question.cpython-39.pyc b/pkg/pkg2/__pycache__/Question.cpython-39.pyc new file mode 100644 index 0000000..33c8a37 Binary files /dev/null and b/pkg/pkg2/__pycache__/Question.cpython-39.pyc differ diff --git a/test-pkg1.ipynb b/test-pkg1.ipynb new file mode 100644 index 0000000..d7c7bf9 --- /dev/null +++ b/test-pkg1.ipynb @@ -0,0 +1,269 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "ec9e763e-6f51-4aca-8e7c-be980b2ec2ee", + "metadata": {}, + "outputs": [], + "source": [ + "from pkg.pkg1 import information_input as ii\n", + "from pkg.pkg1 import information_output as io\n", + "from pkg.pkg1 import information_check as ic\n", + "from pkg.pkg2 import Checking as ch\n", + "from pkg.pkg2 import Course as co\n", + "from pkg.pkg2 import Question as qu" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d9013e12-ed52-4773-a565-059d84fa4f5b", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "test_student (__main__.Test_output) ... ok\n", + "test_teacher (__main__.Test_output) ... ok\n", + "\n", + "----------------------------------------------------------------------\n", + "Ran 2 tests in 0.002s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set Up\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import unittest\n", + "\n", + "class Test_output(unittest.TestCase):\n", + " \n", + " def setUp(self): \n", + " print('Set Up')\n", + " self.student_name= 'lily'\n", + " self.student_ID= 9130\n", + " self.student_major='MDS'\n", + " self.student_degree='Post'\n", + " self.teacher_name= 'John'\n", + " self.teacher_ID= 7788\n", + " self.teachr_research='maching learning'\n", + " self.teacher_length=5\n", + " \n", + " def tearDown(self):\n", + " print('Tear Down')\n", + " \n", + " def test_student(self):\n", + " p1= io.Student(self.student_name,self.student_ID,self.student_major,self.student_degree)\n", + " p2 = io.Group(self.student_name,self.student_ID)\n", + " \n", + " self.assertEqual(p1.major,self.student_major)\n", + " self.assertEqual(p1.degree,self.student_degree)\n", + " self.assertEqual(p2.name,self.student_name)\n", + " self.assertEqual(p2.ID,self.student_ID)\n", + " \n", + " def test_teacher(self):\n", + " p3= io.Teacher(self.teacher_name,self.teacher_ID,self.teachr_research,self.teacher_length)\n", + " p4 = io.Group(self.teacher_name,self.teacher_ID)\n", + " \n", + " self.assertEqual(p3.research,self.teachr_research)\n", + " self.assertEqual(p3.length,self.teacher_length)\n", + " self.assertEqual(p4.name,self.teacher_name)\n", + " self.assertEqual(p4.ID,self.teacher_ID)\n", + " \n", + " \n", + "unittest.main(argv=[''], verbosity=2, exit=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "cfec5248-819d-4a63-a068-dcdc46b8c898", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "test_check_IsNull (__main__.Test_check) ... ok\n", + "test_check_inlist (__main__.Test_check) ... ok\n", + "test_student (__main__.Test_output) ... ok\n", + "test_teacher (__main__.Test_output) ... ok\n", + "\n", + "----------------------------------------------------------------------\n", + "Ran 4 tests in 0.006s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "1\n", + "2\n", + "Set Up\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "class Test_check(unittest.TestCase):\n", + " \n", + " def setUp(self): \n", + " print('1')\n", + " self.right_name = 'lily'\n", + " self.right1_name = 'Justin'\n", + " self.right2_name = 'Travis'\n", + " self.wrong_name = ''\n", + " self.right_id = \"12345\"\n", + " self.right2_id = \"54321\"\n", + " self.wrong_id = \"36345\"\n", + " self.wrong2_id = \"\"\n", + " \n", + " def tearDown(self):\n", + " print('2')\n", + " \n", + " def test_check_inlist(self): #function\n", + " right = ic.Info_Check(self.right_name,self.right_id)\n", + " wrong = ic.Info_Check(self.wrong_name,self.wrong_id)\n", + " right2 = ic.Info_Check(self.right2_id,self.right_id)\n", + " wrong2 = ic.Info_Check(self.wrong_name,self.wrong_id)\n", + " \n", + " self.assertTrue(right.check_inlist())\n", + " self.assertFalse(wrong.check_inlist())\n", + " self.assertTrue(right2.check_inlist())\n", + " self.assertFalse(wrong2.check_inlist())\n", + " \n", + " \n", + " def test_check_IsNull(self):\n", + " right = ic.Info_Check(self.right_name,self.right_id)\n", + " wrong = ic.Info_Check(self.wrong_name,self.right_id)\n", + " right1 = ic.Info_Check(self.right1_name,self.right_id)\n", + " right2 = ic.Info_Check(self.right2_name,self.right_id)\n", + " \n", + " self.assertFalse(right.check_IsNull())\n", + " self.assertTrue(wrong.check_IsNull())\n", + " self.assertFalse(right1.check_IsNull())\n", + " self.assertFalse(right2.check_IsNull())\n", + " \n", + "unittest.main(argv=[''], verbosity=2, exit=False)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "5a82e66d-7dd1-432f-93d3-0e5e2edcb132", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....\n", + "----------------------------------------------------------------------\n", + "Ran 4 tests in 0.004s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set Up\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n", + "Tear Down\n", + "Tear Down\n", + "\n" + ] + } + ], + "source": [ + "def my_suite():\n", + " suite = unittest.TestSuite()\n", + " result = unittest.TestResult()\n", + " suite.addTest(unittest.makeSuite(Test_output))\n", + " suite.addTest(unittest.makeSuite(Test_check))\n", + " runner = unittest.TextTestRunner()\n", + " print(runner.run(suite))\n", + "my_suite()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "71012f5e-8e9e-4aaa-b39b-17e8a77d97c6", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "146e20e9-9d64-4313-b015-295ce7794071", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/test-pkg2.ipynb b/test-pkg2.ipynb new file mode 100644 index 0000000..714ff19 --- /dev/null +++ b/test-pkg2.ipynb @@ -0,0 +1,183 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "6d332b6c-bde2-4bdd-8ca2-ce3e094433e7", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + ".....\n", + "----------------------------------------------------------------------\n", + "Ran 5 tests in 0.003s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set Up\n", + "Correct answer is: 3\n", + "\n", + "Wrong :( \n", + " \n", + " \n", + "\n", + "The correct answer is: 0\n", + "\n", + "Correct!!! \n", + " \n", + " \n", + "\n", + "Wrong :( \n", + " \n", + " \n", + "\n", + "The correct answer is: 0\n", + "\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n", + "Set Up\n", + "Tear Down\n", + "\n" + ] + } + ], + "source": [ + "from pkg.pkg1 import information_input as ii\n", + "from pkg.pkg1 import information_output as io\n", + "from pkg.pkg2 import Checking as ch\n", + "from pkg.pkg2 import Course as co\n", + "from pkg.pkg2 import Question as qu\n", + "\n", + "def addition(num1, num2):\n", + " return num1 + num2\n", + "\n", + "# Checking.py\n", + "import unittest\n", + "class TestCheck(unittest.TestCase):\n", + " def setUp(self): # Setting up for the test \n", + " print('Set Up')\n", + " self.teacher_have_data = co.Course([{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"3\",\"difficulty\": \"easy\"}],\" \", \"teacher\")\n", + " self.teacher_have_no_data = co.Course([],\" \", \"teacher\")\n", + " self.student_have_data = co.Course([{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"3\",\"difficulty\": \"easy\"}],\" \", \"student\")\n", + " self.student_have_no_data = co.Course([],\" \", \"student\")\n", + " \n", + " def tearDown(self):\n", + " print('Tear Down')\n", + " \n", + " def test_isEmpty(self):\n", + " self.assertTrue(self.teacher_have_data.isEmpty())\n", + " self.assertFalse(self.teacher_have_no_data.isEmpty())\n", + " self.assertTrue(self.student_have_data.isEmpty())\n", + " self.assertFalse(self.student_have_no_data.isEmpty())\n", + " \n", + " def test_check_answer(self):\n", + " self.assertTrue(self.teacher_have_no_data.check_answer(\"3\",\"3\"))\n", + " self.assertFalse(self.teacher_have_no_data.check_answer(\"3\",\"0\"))\n", + " self.assertTrue(self.student_have_data.check_answer(\"3\",\"3\"))\n", + " self.assertFalse(self.student_have_data.check_answer(\"3\",\"0\"))\n", + "\n", + " \n", + "# Course.py\n", + "class TestCourse(unittest.TestCase):\n", + " def setUp(self): # Setting up for the test \n", + " print('Set Up')\n", + " self.correct_question = \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\"\n", + " self.data1 = [{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"3\",\"difficulty\": \"easy\"}]\n", + " self.data2 = [{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"4\",\"difficulty\": \"normal\"}]\n", + " self.data3 = [{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"5\",\"difficulty\": \"hard\"}]\n", + " self.data4 = [{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"6\",\"difficulty\": \"\"}]\n", + " self.teacher_have_data1 = co.Course([{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"3\",\"difficulty\": \"easy\"}],\" \", \"teacher\")\n", + " self.teacher_have_data2 = co.Course([{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"4\",\"difficulty\": \"normal\"}],\" \", \"teacher\")\n", + " self.teacher_have_data3 = co.Course([{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"5\",\"difficulty\": \"hard\"}],\" \", \"teacher\")\n", + " self.teacher_have_data4 = co.Course([{ \"question\": \"How many of the following statements are TRUE?(Answer in Number) \\n1) Git is a is distributed version control system \\n2) Git is designed to support parallel development \\n3) Git is a web-based repository Service \\n4) Git doesn’t require a server \\n\",\"correct_answer\": \"6\",\"difficulty\": \"\"}],\" \", \"teacher\")\n", + " \n", + " def tearDown(self):\n", + " print('Tear Down')\n", + " \n", + " def test_append_text(self):\n", + " for question in self.data1:\n", + " self.assertEqual(self.teacher_have_data1.append_text(question), self.correct_question)\n", + " \n", + " def test_append_answer(self):\n", + " for question in self.data1:\n", + " self.assertEqual(self.teacher_have_data1.append_answer(question), \"3\")\n", + " for question in self.data2:\n", + " self.assertEqual(self.teacher_have_data2.append_answer(question), \"4\")\n", + " for question in self.data3:\n", + " self.assertEqual(self.teacher_have_data3.append_answer(question), \"5\")\n", + " for question in self.data4:\n", + " self.assertEqual(self.teacher_have_data4.append_answer(question), \"6\")\n", + "\n", + " def test_append_difficulty(self):\n", + " for question in self.data1:\n", + " self.assertEqual(self.teacher_have_data1.append_difficulty(question), \"easy\")\n", + " for question in self.data2:\n", + " self.assertEqual(self.teacher_have_data2.append_difficulty(question), \"normal\")\n", + " for question in self.data3:\n", + " self.assertEqual(self.teacher_have_data3.append_difficulty(question), \"hard\")\n", + " for question in self.data4:\n", + " self.assertEqual(self.teacher_have_data4.append_difficulty(question), \"\")\n", + "\n", + " \n", + "def my_suite():\n", + " suite = unittest.TestSuite()\n", + " result = unittest.TestResult()\n", + " suite.addTest(unittest.makeSuite(TestCheck))\n", + " suite.addTest(unittest.makeSuite(TestCourse))\n", + " runner = unittest.TextTestRunner()\n", + " print(runner.run(suite))\n", + "my_suite()\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "547be72f-c484-4b98-9a4b-a2807ea20322", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72b68cf8-ea4d-4d33-9f8e-44f4f9ed5876", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}