Python Programming _ Question Bank (1)
Python Programming _ Question Bank (1)
Unit1:-
1) Differentiatethelocalandglobal variable.
2) ExplaintheconceptofPythonvariables.Provideexamplestoillustratethedeclaration and
use of variables in Python.
3) WhatwillbetheoutputofthefollowingPythoncode? i = 0
while i<3:
print(i)
i += 1
else:
print(0)
4) Explainalltheconditionalstatement inPythonusingsmallcodeexample.
5) Whatdoyoumean bythePythonIDE's.
6) Whatdoyoumeanbyoperator?Explainthecategoryofoperatorswithpythonprogram in
detail.
7) WhatisPython?HowPythonisinterpreted?
8) Writeshortnoteswithexample:
Theprogrammingcycleforpython
ElementsofPython
TypeconversioninPython
Operatorprecedence
Boolean expression.
9) HowmemoryismanagedinPython?ExplainPEP8.
10) WriteaPythonprogramtoprintevenlengthwordsinastring.
11) Whatwill betheoutput offollowingprint statements?
a. print('abc'*2)
b. print(3+4j+2+1j)
c. print(3*2 // 4)
12) WhatwillbetheoutputofthefollowingPythoncode? def
cube(x):
returnx*x*x x
= cube(3)
printx
13) Explainwhytheprogramgeneratesan error.
x=[‘12’,’hello’,456]
x[0]*=3
x[1][1]=’bye’
a, b = 4,5,6 # s2
u= 7,8,9 # s3
Unit2:-
1) Writeapurposetousebreak andcontinuestatements,explainwith examples.
2) What is the output of print tuple + tinytuple if tuple = ('abcd', 786 , 2.23, 'john', 70.2)
and tinytuple = (123, 'john') ?
3) Whatisthe outputofprint tuple[1:3]
iftuple=( 'abcd', 786, 2.23,'john', 70.2)?
4) Givethe output offollowingPythoncode:
L=[(x,y)forxin[1,2,3]foryin[3,1,4]ifx!=y] print (L)
5) Whatis the meaningof rangefunction, and how to useit, explain with example?
6) Writethesyntaxofif-elsestatement,andwriteaprogramtocheckwhetherthe entered
number is even or odd.
7) Statewhich ofthefollowingpython statementsarevalidand invalid.
a. x =input("entera number")
b. x=input()
c. x=input("")
d. x=input("'")
e. x=input(2)
f. x=input("2"+"3")
8) Differentiatebetween numeric data types in Python. Provideexamples demonstrating
their use.
9) ExplaintheconditionalblocksinPythonusingif,else,andelseifstatements.Provide a code
example illustrating their usage.
10) Explain the purpose and working of loops. Discuss break and continue with example.
Write a Python program to convert time from 12 hour to 24-hour format.
11) Writeaprogramtofindafactorialofanumberusingloop.
12) Computetheoutputofthefollowingpythoncode: def
count(s):
forstrin string.split():
s=“&”.join(str)
returns
print(count(“Pythonisfuntolearn.”))
1. Returnalistofnumbersstartingfromthelasttoseconditemofthe list
2. Returnalistthatstartfrom3rditemtosecondlastitem.
3. ReturnalistthathasonlyevenpositionelementsoflistLtolist M.
4. ReturnalistthatstartsfromthemiddleofthelistL.
5. Returnalistthatreversesalltheelementsstartingfromelementatindex
Unit3:-
1) Explainthe concept of list in Python and demonstrate list slicing. Provide examplesof
list manipulation.
2) DiscussfunctioninPythonwithitspartsandscope.Explainwithexample.(Take simple
calculator with add, subtract, division and multiplication).
3) Writeaprogramthatreversesagiven string.
4) Explainunpackingsequences,mutablesequences,andlistcomprehensionwith example.
5) Definethe lambdafunction for python.
6) WriteaprogramtosortlistofdictionariesbyvaluesinPython-Usinglambda function.
7) Whatdoyoumeanbyinbuiltfunction?Explaintheinbuiltmethodsoflistwith suitable
example.
8) Writeaprogramtosortthecharactersofthestring,firstalphabetsymbolsfollowedby
numeric values.
9) Howarecomplexdatatypes(string,list,anddictionary)manipulatedinPython? Provide
examples of programming using these in-built functions.
10) Discussfunctioninpythonits partsandscope.Create acalculatorusingpython.
11) Write a function that takes a string as input and returns the count of vowels present in
it.
12) Write a Python program which will return the sum of the numbers in the array,
returning 0 for an empty array. Except the number 13 is very unlucky, so it does not
count and number that come immediately after 13 also do not count.
Example:[1, 2,3, 4] =10
[1, 2, 3, 4, 13]= 10
[13, 1, 2, 3, 13]= 5
13) Considerthelistlst=[9,8,7,6,5,4,3].WritethePythonprogramwhichperformsthe following
operation without using built-in methods.
1) Insertelement10atbeginningofthe list.
2) Insertelement2atend ofthe list.
3) Deletetheelementat indexposition 5.
4) Printallelementsinreverse order.
14) Implement a Python script that takes a list of numbers as input and returns a new list
containing only the even numbers.
15) Write a python program to implement isPalindrome() function to check given
stringispalindrome or not.
16) WriteaPythonprogramtoconstructthefollowingpattern,usinga
nested for loop.
*
**
* **
* * **
* ****
****
***
**
*
20) Constructfollowingfilters:
1. Filterallthenumbers
2. Filterall thestrings startingwith a vowel
3. Filterallthestringsthatcontainsanyofthefollowingnoun:Agra,Ramesh,Tomato,
Patna.
Createaprogram thatimplements thesefiltersto cleanthetext.
Unit4:-
1) Writeaprogramthattakesuser-inputandappends ittoanexistingfile.
2) Writethedifferencebetweenwritelineandwritelinesfunctions.
3) Discussvarious fileopeningmodes ofpython.
4) Describethevarious readmethods of afilewith suitableexamplein detail.
5) Explainthe following file built-in function and methods with clear syntax,description
and illustration: a)open b)file c)seek d)tell
6) Write a python program to read line by line from a given files file1 & file2 and write
into file3.
7) Writeapythonprogramthatreadsatextfilecontainingfull-nameoftheemployeesof a
company and then from these names it extracts Last-name of employee and stores
them in sorted order in new file. Input Text file contains names in format: First-name
Middle-name Last-name
8) Describe file operations in Python. Explain read functions (readO, readline),readlines)
and writefunctions (write, writelines) with examples.
9) CreateaPythonprogramtoreadatext fileanddofollowing:
1. Print no. of lines
2. Print no. of uniquewords
3. Storeeachwordwithitsoccurrenceindictionary
10) Construct a program which accepts a sequence of words separated by whitespace
asfile input. Print the words composed of digits only.
Unit5:-
1) WhatarepackagesinPyhton?
2) Explainwhatis meantbynamespacesandscoping.
3) Whatdoyou mean bytheTkWidgets?
4) HowCanYouCreateanEmptyDataframeinPandas?
5) HowcanyoucreateaPandasDataFramefromaPythondictionary?
6) Use the numpy library to perform basic array operations (e.g., addition,
multiplication) on twoarrays.
7) Describe the difference between import library and from library import * when usedin
a python program. Here library is some python library.
8) Construct a program to read cities.csv dataset, remove last column and save it in
anarray. Save the last column to another array. Plot the first two columns.
9) Describeaboutdifferent functionsofmatplotliband pandas.