0% found this document useful (0 votes)
22 views10 pages

2.4 Output Sheet of Function

The document contains a series of Python function definitions and their respective calls, showcasing various programming concepts such as default parameters, global variables, and loops. Each question demonstrates different functionalities, including mathematical operations, string manipulations, and list handling. The document serves as a practical exercise for understanding Python programming syntax and behavior.

Uploaded by

mishrarajesh1541
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

2.4 Output Sheet of Function

The document contains a series of Python function definitions and their respective calls, showcasing various programming concepts such as default parameters, global variables, and loops. Each question demonstrates different functionalities, including mathematical operations, string manipulations, and list handling. The document serves as a practical exercise for understanding Python programming syntax and behavior.

Uploaded by

mishrarajesh1541
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Output sheet of function

Q1.
def Location(X, Y = 4):
X+=2
Y+=X
print(X, Y)
PX = 10
PY = 2
Location(PY)
Location(PX,PY)

Q2.
def Position(C1, C2 = 3):
C1 + = 4
C2 + = C1
print(C1, C2)
Position(5)
P1 = 20
P2 = 4
Position(P1)
Position(P1, P2)

Q3.
def Draw(N, Mark = ’#’):
for I in range(1, N+1):
print(Mark, end=’ ‘)
count = 3
1
sign = ’*’
Draw(count)
Draw(count, sign)
Draw(count, ’&’)

Q4.
def IN(x, y, z):
x+=y
y-=1
z*=(x–y)
print(x, y, z)
def Out(z, y, x):
x*=y
y+=1
z // = ( x + y )
print(x, y, z)
a, b, c=20, 30, 10
Out(a, c, b)
IN(b, c, a)
Out(a, b, c)

Q5.
def Line( ):
for L in range(1, 8):
print(end = ’-’)
def Line(N):
for L in range(1, N):
print(end = ’*’)
2
def Line(C, N):
for L in range(1, N):
print(C, end = ’ ’)
A, B, C=9, 4, ’#’
Line( )
Line(B)
Line(C, A)

Q6.
def stock( ):
global i, r, d
I = 1001
r = 200
d=1
def regcode(I, R):
global i, r
i=I
r=R
def change(n, dt):
global r, d
r+=n
d = dt
def show( ):
print(‘Date : ’, d, end = ’ :’)
print(i, ’#’ ,r)
stock( )
show( )
regcode(1024, 150)
3
change(100, 29)
show( )
regcode(2015, 300)
change(-20, 20)
show( )

Q7.
def Share( ):
global Code, Rate, DD
Code = 1000
Rate = 100
DD = 1
def GetCode(C, R):
global Code, Rate
Code = C
Rate = R
def Update(Change, D):
global Rate, DD
Rate + = Change
DD = D
def Status( ):
print(’Date : ’, DD, end=’:‘)
print(Code, ’#’, Rate)
Share( )
Status( )
GetCode(1324, 350)
Update(50, 28)
Status( )
4
GetCode(1435, 250)
Update(-25, 26)
Status( )

Q8.
def Eval( ):
global Level, Point
Level = ’E’
Point = 0
def Sink(L):
global Level
Level = chr ( ord ( Level ) – L )
def Float(L):
global Level, Point
Level = chr ( ord ( Level ) + L )
Point + = 1
def Show( ):
print(Level, ’#’, Point)
Eval( )
Show( )
Sink(3)
Show()
Float(7)
Show()
Sink(2)
Show()
Float(5)
Show()
5
Q9.
def Item( ):
global Ino, Iname, Price
Ino = 100
Iname = None
Price = 100
def Assign(I, Name, P):
global Ino, Iname, Price
Ino + = I
Iname = Name
Price = P
def RaiseP(P):
global Price
Price + = P
def ReduceP(P):
global Price
Price - = P
def Disp( ):
print( Ino, ’:’, Iname, ’:’, Price)
Item( )
Disp( )
Assign(1, ’Pen’, 95)
RaiseP(10)
Disp( )
Assign(2, ’Pencil’, 55)
ReduceP(5)
Disp( )

6
Q10.
def Player(GGame = ’A’):
global Score, Level, Game
Score = 0
Level = 1
Game = GGame
def Start(SC):
global score, Level
Score + = SC
if Score >= 100:
Level = 3
elif Score >= 50:
Level = 2
else :
Level = 1
def Next( ):
global Game
if Game == ’A’:
Game = ’B’
else:
Game=’A’
Def Disp( ):
print(Game, ’@’, Level)
print(Score)
Player( )
Disp( )
Start(120)
Disp( )
7
Player(‘B’)
Start(75)
Next( )
Disp( )

Q11.
def Aroundus(P = 2):
global Place, Humidity, Temp
Place = P
Humidity = 60
Temp=20
def Hot(T):
global Temp
Temp + = T
def Humid(H):
global Humidity
Humidity + = H
def JustSee( ):
print(Place, ’:’, Temp, ’&’, Humidity, ’%’)
Aroundus( )
Hot(10)
JustSee( )
Humid(5)
JustSee( )
Aroundus(5)
Humid(15)
Hot(2)
JustSee( )
8
Q12.
import random
Courses = [‘M.Tech’, ’MCA’, ’MBA’, ’BCA’]
for i in range(1,4):
ch=random.randrange(i)+1
print( courses [ch], end = ’\t’)
(i) Out of all the four courses stored in the variable courses, which course will never be
displayed in the output and which course will always be displayed at first in the output ?
(ii) Mention the minimum and maximum value assigned to the variable ch.

Q13.
def ChangeList ( Number, ARR, Size ) :
for L in ramge(Size):
if L < Number:
ARR[L] + = L
else:
ARR[L] * = L
return ARR
Array = [30, 20, 40, 10, 60, 50]
print(ChargeList ( 3, Array, 6) )

Q14.
def Mycode ( Msg, CH ):
st=’’
for cnt in range ( len(Msg) ):
if Msg[cnt] >= ’B’ and Msg[cnt] <= ’G’:
st += Msg[cnt].lower()
else:
9
if Msg[cnt] == ’N’ or Msg[cnt] == ’n’ or Msg[cnt] == ’ ’ :
st = st + CH
else:
if cnt % 2 == 0:
st += Msg[cnt].upper()
else:
st += Msg[cnt-1]
print(st)
MyText = ’Input Raw’
MyCode ( MyText, ’@’ )

Q15.
def ChangeIt( Text, C ):
s=’’
for k in range( len(Text) ):
if Text[k] >= ’F’ and Text[k] <= ’L’:
s = s + Text[k].lower()
else:
if Text[k] == ’E’ or Text[k] == ’e’:
s=s+C
else:
if k % 2 == 0:
s = s + Text[k].upper()
else:
s = s + Text[k-1]
return s
OldText = ’pOwERALone’
print( ChangeIt ( OldText, ’X’ )
10

You might also like