Skip to content

Commit 692de0b

Browse files
committed
Update functions_ikram_celal_keskin.py
Deleted global variables
1 parent 8b98eff commit 692de0b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Week04/functions_ikram_celal_keskin.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11

22

3-
4-
count= 0
5-
caller_dict= {}
6-
7-
8-
93
custom_power= lambda x=0,/,e=1: x**e
104

115
def custom_equation(x:int=0,y:int=0,/,a:int=1,b:int=1,*,c:int=1)->float:
@@ -29,26 +23,29 @@ def custom_equation(x:int=0,y:int=0,/,a:int=1,b:int=1,*,c:int=1)->float:
2923
"""
3024
return (x**a + y**b) / c
3125

26+
27+
3228
def fn_w_counter()->(int, dict[str, int]):
3329
"""
3430
This funtion counts the how many times it is called and from which caller it is called.
3531
3632
:return: Returning integer is the total number of calls and Returning dictionary with string keys and integer values includes the caller ( _ _name_ _ ) as key, the number of call coming from this caller as value.
3733
:rtype: tuple(int, dict[str, int])
3834
"""
39-
global count
40-
global caller_dict
35+
if not hasattr(fn_w_counter, "count"):
36+
setattr(fn_w_counter,"count",0)
37+
setattr(fn_w_counter,"caller_dict",{})
38+
4139

42-
count += 1
40+
fn_w_counter.count += 1
4341
caller= __name__
4442

45-
if caller not in caller_dict:
46-
caller_dict[caller] = 0
43+
if caller not in fn_w_counter.caller_dict:
44+
fn_w_counter.caller_dict[caller] = 0
4745

48-
caller_dict[caller] += 1
49-
50-
return (int(count),dict(caller_dict))
46+
fn_w_counter.caller_dict[caller] += 1
5147

48+
return (int(fn_w_counter.count),dict(fn_w_counter.caller_dict))
5249

5350

5451

0 commit comments

Comments
 (0)