Skip to content

Commit cd00052

Browse files
authored
Merge pull request #1 from utkarsh-sharma/master
Create Assignment-2_Soln.txt
2 parents 7810cb6 + 9eab074 commit cd00052

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

Assignment-2_Soln.txt

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Questions
2+
3+
Write a function which returns max of 2 numbers. We can use if, elif and else, right?
4+
Find the output - Concept of local and global variables
5+
6+
a = 60
7+
def func(z):
8+
print("z = ", z)
9+
a = 2
10+
print('Changed local a to', a)
11+
func(a)
12+
print('Global a is still', a)
13+
What is the use of id(), print() function in python? You know the interpreter trick!
14+
15+
What's the output:
16+
17+
def cube(x):
18+
return x * x * x
19+
20+
x = cube(3)
21+
print x
22+
Lets find the output , again! :smiley:
23+
24+
def foo(k):
25+
k[0] = 1
26+
27+
q = [0]
28+
foo(q)
29+
print(q)
30+
Try this, find output?
31+
32+
def foo(i, x=[]):
33+
x.append(x.append(i))
34+
return x
35+
for i in range(3):
36+
y = foo(i)
37+
print(y)
38+
39+
40+
Answers
41+
42+
1. Answer
43+
44+
def maxno(a,b):
45+
if(a>b)
46+
return a
47+
else
48+
return b
49+
2. Answer
50+
51+
z = 60
52+
Changed local a to 2
53+
Global a is still 60
54+
55+
3. Answer
56+
57+
id() returns the identity of an object.
58+
print() prints the values to a stream.
59+
60+
4.Answer
61+
62+
27
63+
64+
5. Answer
65+
66+
[1]
67+
68+
6. Answer
69+
70+
[0, None, 1, None, 2, None]
71+
72+
73+
74+

0 commit comments

Comments
 (0)