PYTHON PROGRAMMING LAB – ALL QUESTION ANSWERS (Q1–Q11)
Q1.A Operators demonstration
CODE:
a = 10
b=3
print(a+b, a-b, a*b, a/b)
Q1.B Sum dictionary values
CODE:
data={"a":10,"b":20,"c":30}
print(sum([Link]()))
Q2.A Length of string
CODE:
s="Hello"
c=0
for i in s: c+=1
Q2.B File count
CODE:
with open("[Link]") as f:
lines=[Link]()
Q2.C Substring check
CODE:
"Python" in "Welcome to Python"
Q3.A Array operations
CODE:
import array
a=[Link]('i',[10,20,30])
Q3.B List functions
CODE:
lst=[5,3,8,1]
Q3.C Add dict pair
CODE:
d={"name":"Sam"}
d["city"]="KKD"
Q4.A Array again
Q4.B Permutations
CODE:
import itertools
Q4.C Reverse file
CODE:
with open("[Link]") as f: ...
Q5.A Sort words
CODE:
with open("[Link]") as f: ...
Q5.B Scatter plot
CODE:
[Link](...)
Q6.A Inclusion–Exclusion
CODE:
A={1,2,3}
Q6.B JSON complex
CODE:
[Link](...)
Q6.C Even odd prime sum
CODE:
def prime(n): ...
Q7.A String length
Q7.B Tuple concatenation
Q7.C NumPy array
Q8.A Shape classes
Q8.B Default args
Q8.C Count vowels
Q9.A Set operations
Q9.B Sympy consistency
Q10.A Complex numbers
Q10.B List ops
Q10.C Graphs
Q11.A NumPy attrs
Q11.B Histogram
Q11.C Bayes theorem