forked from pruthvz/PyAPIReference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
129 lines (93 loc) · 3.69 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""Example file with classes, iheritance, functions, imported members and constants to test PyAPIReference.
This is the docstring for example.py.
"""
from time import sleep
from PyQt5 import *
BLACK = "#000000"
WHITE = "#ffffff"
class Person:
"""Class person that requires name, last name and age.
Allows you to display some info about it.
"""
human = True
def __init__(self, name: str, last_name: str, age: str):
self.name = name
self.last_name = last_name
self.age = age
pineapple = False
def display_info(self):
print(f"Hello, my name is {self.name} {self.last_name} I have {self.age} years old.\n")
class Student(Person):
"""Class Student that inherits from Person and requires grade and institution (besides the Person ones).
Allows you to display some info about it.
"""
studying = True
def __init__(self, grade: int, institution: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.grade = grade
self.institution = institution
def display_info(self):
print(f"Hello, my name is {self.name} {self.last_name} I have {self.age} years old.\nI'm a student of grade {self.grade} in {self.institution}\n")
class Teacher(Person):
"""Class Teacher that inherits from Person and requires instituiton and classes (besides Person ones).
Alloes you to display some info about it.
"""
def __init__(self, institution: str, classes: tuple, *args, **kwargs):
super().__init__(*args, **kwargs)
self.institution = institution
self.classes = classes
def display_info(self):
print(f"Hello, my name is {self.name} {self.last_name} I have {self.age} years old.\nI'm a teacher of {''.join(self.classes)} in {self.institution}\n")
class SchoolTeacher(Teacher):
"""Class SchoolTeacher that inherits from Teacher and requires grades.
Allows you to display some info about it."""
def __init__(self, grades: tuple, *args, **kwargs):
super().__init__(*args, **kwargs)
self.grades = grades
def display_info(self):
print(f"Hello, my name is {self.name} {self.last_name} I have {self.age} years old.\nI'm a teacher of {''.join(self.classes)} in {''.join(self.grades)} at {self.institution}\n")
class CollegeStudent(Student):
"""Class CollegeStudent that inherits from Student and requires career and semester (besides the Student ones).
Allows you to display some info about it.
"""
def __init__(self, career: str, semester: int, *args, **kwargs):
super().__init__(*args, **kwargs)
self.career = career
self.semester = semester
def display_info(self):
print(f"Hello, my name is {self.name} {self.last_name} I have {self.age} years old.\nI'm a college student of {self.career}, I'm on {self.semester} semester\n")
class Me(Teacher, CollegeStudent):
"""I'm a teacher on a school but a student in a college."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def caesar_cipher(text: str, shift: int=5) -> str:
"""Simple caesar cipher function that encrypts a string with using caesar cipher.
"""
result = ""
for char in text:
if (char.isupper()):
result += chr((ord(char) + shift - 65) % 26 + 65)
continue
result += chr((ord(char) + shift - 97) % 26 + 97)
return result
def foo(param1, param2=None, param3: str="Hello world"):
"""foo function docstring"""
pass
def emtpy():
pass
'''
unsafe tests. Delete if name == main
emtpy()
x = Person("name", "last_name", "age").display_info()
foo(1)
y = foo
y()
'''
if __name__ == "__main__":
person = Person("William", "Polo", 15)
student = Student(6, "Harward", "Jack", "Sparrow", 45)
college_student = CollegeStudent("Computer science", 4, 0, "Harvard", "Will", "Miles", 23)
person.display_info()
student.display_info()
college_student.display_info()
print(caesar_cipher(person.name))