-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathassignment_26_01.py
85 lines (58 loc) · 1.78 KB
/
assignment_26_01.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
# 1. Create a class called "oddeven" that prints if a number is odd or even in a range of 20.
class OddEven:
def __init__(self, start, end):
self.start = start
self.end = end
def oddeven(self):
for i in range(self.start, self.end):
if i % 2 == 0:
print(i, "is even")
else:
print(i, "is odd")
# 2. Create a class that uses a user input to print out your output.
class UserInput:
def __init__(self):
self.input = input("Enter a number: ")
def userinput(self):
print(f"user input is: {self.input}")
# 3. .Create a class that has 3 child classes that inherits from the parent class.
class Parent:
def __init__(self, name):
self.name = name
def print_name(self):
print(f"Parent class name is: {self.name}")
class Child1(Parent):
def __init__(self, name):
super().__init__(name)
def print_name(self):
print(f"Child1 class name is: {self.name}")
class Child2(Parent):
def __init__(self, name):
super().__init__(name)
def print_name(self):
print(f"Child2 class name is: {self.name}")
class Child3(Parent):
def __init__(self, name):
super().__init__(name)
def print_name(self):
print(f"Child3 class name is: {self.name}")
# 4. Create a whileloop that is counting down from 10 to 1.
def countdown():
i = 10
while i > 0:
print(i)
i -= 1
def main():
odd_even = OddEven(1, 20)
odd_even.oddeven()
user_input = UserInput()
user_input.userinput()
child1 = Child1("Child1")
child2 = Child2("Child2")
child3 = Child3("Child3")
child1.print_name()
child2.print_name()
child3.print_name()
countdown()
if __name__ == '__main__':
main()