0% found this document useful (0 votes)
9 views

Assignment function

The document outlines a series of programming assignment questions focused on functions in Python. It covers topics such as argument types, the use of global variables, return statements, and various coding tasks including list manipulation and output prediction. Each question requires explanations, examples, or coding solutions related to Python functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Assignment function

The document outlines a series of programming assignment questions focused on functions in Python. It covers topics such as argument types, the use of global variables, return statements, and various coding tasks including list manipulation and output prediction. Each question requires explanations, examples, or coding solutions related to Python functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMENT: FUNCTIONS

1. What is the difference between Actual argument and Format argument? Explain with example
2. What is positional argument? Give example
3. What is the use of global keyword used in a function with the help of suitable example
4. Is return statement is compulsory in python function? How many values a return statement can return at a
time? If return statement is not used inside a function, what will be the return value of the function ?
5. Trace the flow of execution of the following program
i. def increment (x)
ii. x=x+1
iii.
iv. # main program
v. X=3
vi. print (x)
vii. increment (x)
viii. print(x)
6. What possible outputs(s) are expected to be displayed on screen at the time of execution of the
program from the following code? Also specify the maximum values that can be assigned to each of
the variables A and B.
import random
AR=[20,30,40,50,60,70,80,90]
A =random.randint(1,4)
B =random.randint(3,7)
for K in range(A, B +1):
print (AR[K],end=”#“)
(i) 30#40#50# (ii) 30#40#50#60# (iii) 50#60#70# (iv) 40#50#70#
7. Give the output of the following
x=3
def myfunc():
global x
x+=2
print(x, end=' ')
print(x, end=' ')
myfunc()
print(x, end=' ')
8. Write output of the following program
def func(x,y=10):
if (x%y==0):
x=x+1
return x
else:
y=y-1
return y
p,q=20,23
q=func(p,q)
print(p,"#",q)
p=func(q)
print(p,"#",q)
9. Write a function Swap(Arr,n ) in Python, which accepts a list Arr of numbers swaps all adjacent elements
of list .
Sample Input Data of the list Arr= [ 10,20,30,40,12,11] Output Arr = [20,10,40,30,11,12]
10. Ram , python programmer ,is working on a project which require him to define a function interest. He
define it as
def interest (Principal ,Rate= 0.15,time) :
But this code is not working, help him to identify the error in the above function and also correct it
11. What is the difference between local and global variable explain with example

12. What is the output of the following program?


def change (a=10):
a+=5
print((“a=”, a)
a = 20
change ( )
print(“a=”,a)
13. writte a function listchange(Arr,n) in python , whohc accepts a list Arr of numbers, the function will
replace the even number by value 10 and multiple odd number by 5.
Sample input data of the list is : [10,20,23,45] output = [10,10,115,225]

14. Write a function lenFOURword(L), where L is the list of elements (list of words) passed as argument to
the function. The function returns another list named ‘indexList’ that stores the indices of all four lettered
word of L.
For example:If L contains [“DINESH”, “RAMESH”, “AMAN”, “SURESH”, “KARN”]
The indexList will have [2, 4]
15. Write a function LeftShift(Numlist, n) in Python, which accepts a list Numlist of numbers and n is a
numeric value by which all elements of the list are shifted to left.
Sample input data of the list : Numlist = [10, 20, 30, 40, 50, 60, 70], n=2
Output Numlist = [30, 40, 50, 60, 70, 10, 20]
16. Find the output of the following
def ChangeVal(M,N):
for i in range(N):
if M[i] %5 == 0:
M[i] //=5
if M[i] %3 == 0:
M[i] //=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
17. What possible output(s) are expected to be displayed on screen at the time of execution of the
program from the following code? Also specify the maximum values that can be assigned to each of
the variable number.
String = “CBSEONLINE”
Number = random.randint(0,3)
N=9
while String[N] ! = ‘L’ :
print (String[N] + String[Number] + “#” , end = ‘ ‘ )
Number = Number + 1
N = N-1
a. ES#NE#IO# ii) LE#NO#ON# iii) NS#IE#LO# iv) ES#NE#IS#

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy