-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.py
More file actions
88 lines (82 loc) · 1.77 KB
/
day5.py
File metadata and controls
88 lines (82 loc) · 1.77 KB
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
# import math as m
# try:
# print(math.pi)
# except NameError:
# print('Exception')
# def divide(x,y):
# try:
# result = x/y
# except ZeroDivisionError:
# print('Division by zero')
# else:
# print('Result is', result)
# finally:
# print('Clap!')
# divide(2,1)
# print()
# divide(2,0)
# # try except
# A = '1'
# B = 2
# try:
# print(A + B)
# except TypeError:
# print('type error')
# A = int(A)
# print(A+B)
# def devide(x,y):
# try:
# result = x /y
# except ZeroDivisionError:
# print('division by zero')
# except:
# print('Exception')
# else:
# print(f'{x:0.1f}/{y:0.1f}={result:0.1f}')
# finally:
# print('Excuting finally clasue')
# for i in range(4):
# if i == 3:
# i='0'
# print(devide(10,i))
# # CLASS
# class MyClass:
# var = 42
# def hello_world():
# return 'Hello, world!'
#
# print(MyClass.var)
# MyClass.var = 23
# print(MyClass.var)
# print(MyClass.hello_world())
# class MyCounter:
# def set(self):
# self.counter = 0
# return self.counter
# C1 = MyCounter()
# C1.set()
# print(C1.counter)
# class MyCounter:
# def __init__(self, value = 0):
# self.counter = value
#
# C1 = MyCounter()
# C2 = MyCounter(45)
# print(C1.counter)
# print(C2.counter)
counter = 100
class MyCounter:
counter = 200
def __init__(self, value = 0):
print("counter:",value)
self.counter = value
def get(self):
return self.counter
def set(self, value):
counter = value
C1 = MyCounter()
C2 = MyCounter(42)
C1.set(10)
print(C1.counter+C2.counter)
print(MyCounter.get(C1)+C2.get())
print(counter)