You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-27
Original file line number
Diff line number
Diff line change
@@ -78,44 +78,46 @@ result = add(a, b)
78
78
79
79
## Questions
80
80
81
-
1. Write a function which returns max of 2 numbers. We can use if, elif and else, right?
81
+
1. Write a function which returns max of 2 numbers. We can use if, elif and else, right?
82
82
2. Find the output - Concept of local and global variables
83
-
```
84
-
a = 60
85
-
def func(z):
83
+
```
84
+
a = 60
85
+
def func(z):
86
86
print("z = ", z)
87
87
a = 2
88
88
print('Changed local a to', a)
89
-
func(a)
90
-
print('Global a is still', a)
91
-
```
92
-
3. What is the use of id(), print() function in python? You know the interpreter trick!
93
-
4. What's the output:
89
+
func(a)
90
+
print('Global a is still', a)
91
+
```
94
92
95
-
```
96
-
def cube(x):
93
+
3. What is the use of id(), print() function in python? You know the interpreter trick!
94
+
4. What's the output:
95
+
96
+
```
97
+
def cube(x):
97
98
return x * x * x
98
99
99
-
x = cube(3)
100
-
print x
101
-
```
102
-
5. Lets find the output , again! :smiley:
103
-
```
104
-
def foo(k):
100
+
x = cube(3)
101
+
print x
102
+
```
103
+
5. Lets find the output , again! :smiley:
104
+
```
105
+
def foo(k):
105
106
k[0] = 1
106
-
q = [0]
107
-
foo(q)
108
-
print(q)
109
-
```
110
-
6. Try this, find output?
111
-
```
112
-
def foo(i, x=[]):
107
+
108
+
q = [0]
109
+
foo(q)
110
+
print(q)
111
+
```
112
+
6. Try this, find output?
113
+
```
114
+
def foo(i, x=[]):
113
115
x.append(x.append(i))
114
116
return x
115
-
for i in range(3):
117
+
for i in range(3):
116
118
y = foo(i)
117
-
print(y)
118
-
```
119
+
print(y)
120
+
```
119
121
120
122
- The trick for solving 'find the output' questions is to NOT think how the program wants to you to think. DON'T proceed with any notion of how that program is *supposed* to work, find out how that program will *exactly* work.
0 commit comments