generated from virtual-labs/ph3-exp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ritance-iitk click on the link to test your code.
- Loading branch information
0 parents
commit cda5ae4
Showing
177 changed files
with
24,609 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
### Aim | ||
|
||
In this experiment, user will learn the concepts of Constructor and Inheritance used in Python programming language. | ||
|
||
### Theory | ||
|
||
Inheritance is a feature that says if you define a new class giving a reference of some other class then due to inheriting property of python your new class will inherit all attributes and behavior of the parent class. | ||
A Constructor is a special kind of method that have same name as the class in python self variable do the same. It can be used to set the values of the members of an object. | ||
|
||
How to define constructor | ||
Syntax: | ||
class class_name | ||
def __init__(self,variable1,variable2) | ||
self.variabl1=variable1 | ||
self.variable2=variable2How to give values to objects using constructors | ||
<br> | ||
Syntax: | ||
Object_name=class_name('variable values',variable values)How to call objects using constructors | ||
<br> | ||
Syntax: | ||
print(Object_name.variable1) | ||
Output: variable value.How to inherit a class | ||
<br> | ||
Syntax: | ||
class class_name(parent class name)How to check whether it is inherited or not | ||
<br> | ||
Syntax: | ||
Object_name = inherited_class_name('variable1,variable2') | ||
print(Object_name.variable1) | ||
Output: variable value. | ||
|
||
### Procedure | ||
|
||
<h4>Steps of simulator </h4><br> | ||
1. Read the Simulator details.<br> | ||
2. Enter the desired input.<br> | ||
4. Press CALCULATE to proceed. <br> | ||
5. The code will be displayed <br> | ||
6. Press NEXT to see the execution of code. <br> | ||
7. Relevant line in the code will be highlighted.<br> | ||
8. The local variables will be shown in the Output Panel with their values.<br> | ||
|
||
### Pre Test | ||
|
||
1. "Which of the following is not a type of inheritance?" | ||
<br> | ||
A.<input type="radio" name="but" id="rb11" onclick="click1();"> Multiple | ||
<br> | ||
B.<input type="radio" name="but" id="rb12" onclick="click1();"> Multi-level | ||
<br> | ||
C.<input type="radio" name="but" id="rb13" onclick="click1();"> Single-level | ||
<br> | ||
D.<input type="radio" name="but" id="rb14" onclick="click1();"> Double-level | ||
<br> | ||
<p id = "p1"></p> | ||
<br> | ||
2. "__del__() is:" | ||
<br> | ||
A. <input type="radio" name="but2" id="rb21" onclick="click2();"> Function | ||
<br> | ||
B. <input type="radio" name="but2" id="rb22" onclick="click2();"> Constructor | ||
<br> | ||
C. <input type="radio" name="but2" id="rb23" onclick="click2();"> Destructor | ||
<br> | ||
D. <input type="radio" name="but2" id="rb24" onclick="click2();"> None of the mentioned | ||
<br><br> | ||
<p id = "p2"></p> | ||
<br> | ||
|
||
3. "Benifits of inheritance are" | ||
<br> | ||
A. <input type="radio" name="but4" id="rb41" onclick="click4();"> Overriding | ||
<br> | ||
B. <input type="radio" name="but4" id="rb42" onclick="click4();"> Data Hiding | ||
<br> | ||
C. Reusability | ||
<br> | ||
D. All of these | ||
<br> | ||
<p id = "p4"></p> | ||
<br> | ||
4."Which of the following is disadvantage of inheritance?" | ||
<br> | ||
A. <input type="radio" name="but3" id="rb31" onclick="click3();"> Coupling | ||
<br> | ||
B. <input type="radio" name="but3" id="rb32" onclick="click3();"> Cohesion | ||
<br> | ||
C. <input type="radio" name="but3" id="rb33" onclick="click3();"> Both A and B | ||
<br> | ||
D. <input type="radio" name="but3" id="rb34" onclick="click3();"> None of these | ||
<br><br> | ||
<p id = "p3"></p> | ||
<br> | ||
5."Python supports multiple inheritance." | ||
<br> | ||
A.<input type="radio" name="but" id="rb11" onclick="click1();"> True | ||
<br> | ||
B.<input type="radio" name="but" id="rb12" onclick="click1();"> False | ||
<br> | ||
|
||
### Post Test | ||
|
||
1. Which of the following statements is true? | ||
<br> | ||
A.<input type="radio" name="but" id="rb11" onclick="click1();"> . The __init__() method is defined in the object class. | ||
<br> | ||
B.<input type="radio" name="but" id="rb12" onclick="click1();"> The __new__() method is defined in the object class. | ||
<br> | ||
C.<input type="radio" name="but" id="rb13" onclick="click1();"> By default, the __new__() method invokes the __init__ method. | ||
<br> | ||
D.<input type="radio" name="but" id="rb14" onclick="click1();"> All of the above | ||
<br> | ||
<p id = "p1"></p> | ||
<br> | ||
|
||
2. Which of the following statements is true? | ||
<br> | ||
A. <input type="radio" name="but2" id="rb21" onclick="click2();"> The __new__() method automatically invokes the __init__ method | ||
<br> | ||
B. <input type="radio" name="but2" id="rb22" onclick="click2();"> The __init__ method is defined in the object class | ||
<br> | ||
C. <input type="radio" name="but2" id="rb23" onclick="click2();"> The __eq(other) method is defined in the object class | ||
<br> | ||
D. <input type="radio" name="but2" id="rb24" onclick="click2();"> The __repr__() method is defined in the object class | ||
<br><br> | ||
<p id = "p2"></p> | ||
<br> | ||
|
||
3. Which of the following is correct? | ||
<br> | ||
A. <input type="radio" name="but4" id="rb41" onclick="click4();"> <br>def __init__(self, personName, personAge):<br> | ||
self.name = personName<br> | ||
self.age = personAge | ||
<br> | ||
B. <input type="radio" name="but4" id="rb42" onclick="click4();"> <br>def __init__(self, personName, personAge):<br> | ||
self.personName = personName<br> | ||
self.personAge = personAge | ||
<br> | ||
C. <input type="radio" name="but4" id="rb43" onclick="click4();"> Both a and b | ||
<br> | ||
D. <input type="radio" name="but4" id="rb44" onclick="click4();"> None of the above | ||
<br><br> | ||
<p id = "p4"></p> | ||
<br> | ||
|
||
|
||
### References | ||
|
||
<p style="font-size:100%; margin-top:2%"> | ||
www.python-course.eu/python3_inheritance.php <br> | ||
interactivepython.org/runestone/static/CS152f17/ClassesBasics/UserDefinedClasses.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
In this experiment, user will learn the concepts of Constructor and Inheritance in Python programming language. | ||
To implement those concepts in solving a simple problem in the simulator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
=/pretest.json | ||
{ | ||
_: [], | ||
f: [ | ||
'/home/runner/work/exp-constructors-and-inheritance-iitk/exp-constructors-and-inheritance-iitk/experiment/pretest.json' | ||
], | ||
files: [ | ||
'/home/runner/work/exp-constructors-and-inheritance-iitk/exp-constructors-and-inheritance-iitk/experiment/pretest.json' | ||
], | ||
c: 'assessment', | ||
contentTypes: 'assessment', | ||
'content-types': 'assessment', | ||
'$0': 'validate' | ||
} | ||
Validated true | ||
=/posttest.json | ||
{ | ||
_: [], | ||
f: [ | ||
'/home/runner/work/exp-constructors-and-inheritance-iitk/exp-constructors-and-inheritance-iitk/experiment/posttest.json' | ||
], | ||
files: [ | ||
'/home/runner/work/exp-constructors-and-inheritance-iitk/exp-constructors-and-inheritance-iitk/experiment/posttest.json' | ||
], | ||
c: 'assessment', | ||
contentTypes: 'assessment', | ||
'content-types': 'assessment', | ||
'$0': 'validate' | ||
} | ||
Validated true |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
.slidecontainer { | ||
text-align: center; | ||
} | ||
|
||
.slider { | ||
width: 10%; | ||
} | ||
|
||
.text-box { | ||
padding: 7px 20px; | ||
margin: 8px 0; | ||
box-sizing: border-box; | ||
width: 14%; | ||
} | ||
|
||
.legend { list-style: none; } | ||
.legend li { padding-bottom : 1.5vw; width: 20vw; } | ||
.legend span { border: 0.1vw solid black; float: left; border-radius: 50%;} | ||
.legend .grey { background-color: grey; } | ||
.legend .green { background-color: #a4c652; } | ||
.legend .black { background-color: black; } | ||
|
||
.button-input { | ||
border-radius: 50vw; | ||
background-color: #288ec8; | ||
border: none; | ||
color: white; | ||
padding: 1%; | ||
margin-left: 1%; | ||
margin-right: 1%; | ||
padding-bottom: 1%; | ||
padding-top: 1%; | ||
padding-left: 2%; | ||
padding-right: 2%; | ||
} | ||
|
||
.button-input:hover { | ||
background-color:gray; | ||
cursor:pointer; | ||
} | ||
|
||
.comment-box { | ||
position: relative; | ||
padding: 1vw; | ||
width: 30vw; | ||
text-align: center; | ||
} | ||
|
||
.instruction-box { | ||
position: relative; | ||
width: 100%; | ||
transition: width 0.2s ease-out; | ||
border: 0.1vw solid grey; | ||
z-index : 10; | ||
} | ||
|
||
.collapsible { | ||
background-color: Transparent; | ||
color: "grey"; | ||
cursor: pointer; | ||
width: 100%; | ||
border: none; | ||
text-align: center; | ||
outline: none; | ||
font-weight: bold; | ||
padding-top: 1%; | ||
padding-bottom: 1%; | ||
} | ||
|
||
.collapsible::-moz-focus-inner { | ||
border: 0; | ||
} | ||
|
||
.active, .collapsible:hover { | ||
background-color: "white"; | ||
} | ||
|
||
/*The unicode \25BE is for ▾ (Dropdown arrow) */ | ||
.collapsible:after { | ||
content: "\25BE"; | ||
color: "grey"; | ||
font-weight: bold; | ||
float: right; | ||
margin-left: 5px; | ||
} | ||
|
||
.active:after { | ||
content: "\25B4"; | ||
} | ||
|
||
.content { | ||
padding: 0 1.8vw; | ||
max-height: 0; | ||
overflow: hidden; | ||
transition: max-height 0.2s ease-out; | ||
background-color: "white"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
.slidecontainer { | ||
text-align: center; | ||
} | ||
|
||
.slider { | ||
width: 10%; | ||
} | ||
|
||
.text-box { | ||
padding: 7px 20px; | ||
margin: 8px 0; | ||
box-sizing: border-box; | ||
width: 14%; | ||
} | ||
|
||
.legend{ | ||
font-size: 1.4vw; | ||
} | ||
.legend { list-style: none; } | ||
.legend li { padding-bottom : 1.5vw; width: 20vw; } | ||
.legend span { border: 0.1vw solid black; float: left; width: 2vw; height: 2vw; margin-right : 0.5vw; border-radius: 50%;} | ||
.legend .grey { background-color: grey; } | ||
.legend .green { background-color: #a4c652; } | ||
.legend .black { background-color: black; } | ||
|
||
.button-input { | ||
border-radius: 50vw; | ||
background-color: #288ec8; | ||
border: none; | ||
color: white; | ||
padding: 1%; | ||
font-size: 1.3vw; | ||
margin-left: 1%; | ||
margin-right: 1%; | ||
padding-bottom: 1%; | ||
padding-top: 1%; | ||
padding-left: 2%; | ||
padding-right: 2%; | ||
} | ||
|
||
.button-input:hover { | ||
background-color:gray; | ||
cursor:pointer; | ||
} | ||
|
||
.comment-box { | ||
position: relative; | ||
padding: 1vw; | ||
width: 30vw; | ||
font-size: 1.5vw; | ||
text-align: center; | ||
} | ||
|
||
.instruction-box { | ||
position: relative; | ||
width: 100%; | ||
transition: width 0.2s ease-out; | ||
border: 0.1vw solid grey; | ||
font-size: 1.5vw; | ||
z-index : 10; | ||
} | ||
|
||
.collapsible { | ||
background-color: Transparent; | ||
color: "grey"; | ||
cursor: pointer; | ||
width: 100%; | ||
border: none; | ||
text-align: center; | ||
outline: none; | ||
font-size: 1.5vw; | ||
font-weight: bold; | ||
padding-top: 1%; | ||
padding-bottom: 1%; | ||
} | ||
|
||
.collapsible::-moz-focus-inner { | ||
border: 0; | ||
} | ||
|
||
.active, .collapsible:hover { | ||
background-color: "white"; | ||
} | ||
|
||
.collapsible:after { | ||
content: '\25BE'; | ||
color: "grey"; | ||
font-weight: bold; | ||
float: right; | ||
margin-left: 5px; | ||
} | ||
|
||
.active:after { | ||
content: "\25B4"; | ||
} | ||
|
||
.content { | ||
padding: 0 1.8vw; | ||
max-height: 0; | ||
overflow: hidden; | ||
transition: max-height 0.2s ease-out; | ||
background-color: "white"; | ||
} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.