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

Python Programming Concepts and Examples

The document contains a series of questions and answers related to programming concepts, data structures, and functions. It includes code snippets, explanations of functions, and various programming scenarios. The content appears to be a compilation of exercises or a test on programming knowledge.

Uploaded by

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

Python Programming Concepts and Examples

The document contains a series of questions and answers related to programming concepts, data structures, and functions. It includes code snippets, explanations of functions, and various programming scenarios. The content appears to be a compilation of exercises or a test on programming knowledge.

Uploaded by

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

Q1.

My_Name
KV2

Q2.
_main
Hello_Dear1

[Link]

Q4.[20,30,40,50]

Q5. optrS

Q6.[48,32,41]

Q7.[27,36]

Q8.[24,23,28]

Q9.[30,24]

Q10. Comma Separated Values

[Link]

Q12.a

[Link]

[Link]()

Q15. The advantage associated with the former format is that we do not need to care
whether the file has been closed at the end or not, the file will get automatically
closed.

Q17.(d)**

Q18.(d)=/

Q19.(d)=<

Q20.(d){"a":1}*2

Q21. 4

Q22.(d)t[1]=5

Q23. (d)list because key should be immutable but list is mutable.

Q24. [Link]() function

Q25. int() function

Q26.
(a)13
(b)True
(c)False
(d)False
(e)True
(f)True

Q27.
(a)uniform() -> random
(b)ceil() -> math
(c)randint() -> random
(d)isalpha() -> string
(e)compile() -> re
(f)randrange() -> random
(g)gcd() -> math
(h)shuffle() -> random
(i)findall() -> re
(j)connect() -> [Link]
(k)floor() -> math
(l)commit() -> [Link]
(m)cursor() -> [Link]

Q28.
(a)string
(b)list
(c)list
(d)dictionary
(e)dictionary,list
(f)string

#Let's take a variable x=("{},How are you?") or "{},how are you?".


After that we pass an argument in format() as [Link](2).
Argument can be an integer,floating point constant,string,characters or even
variables.

Output: "2,How are you?"

(g)string
(h)dictionary

Q29.
(a)Minimum value:0
(b)Maximum value:15

Q30.
(a)ceil([Link]()) gives 1
(b) Minimum value given by [Link]()
is 0.1
Maximum value given by [Link]()
is 0.9

Q31.
(a) "HelloHelloHello"
(b)[10,12,15,10,12,15]
(c)"Hellothere"
(d)[1,2,3,4,5,6]

Q32.
To=30
for K in range(0,To):
if K%4==0:
print(K*4)
else:
print(K+3)
Q33.
Number=250
while Number<=1000:
if Number>=750:
print(Number)
Number+=100
else:
print(Number*2)
Number+=50
Q34.
a=200
b=33
if b>a:
print("b is greater than a")
elif a==b:
print("a and b are equal")
else:
print("a is greater than b")

Q35.
def execmain():
x = int( input("Enter a number:"))
if (abs(x)==x):
print("You entered a positive number")
else:
x*=-1
print("Number made positive :",x)

execmain()

Q36.
Num=int(input("Number:"))
s=0
for i in range(1,Num,3):
s+=1
if i%2==0:
print(i*2)
else:
print(i*3)
print(s)
Q37.
def func(a):
for i in range(0,a):
if i%2==0:
s=s+1
elif i%5==0:
m=m+2
else:
n=n+i
print(s,m,n)

Q38.
x=int(input("Enter value for x:"))
for y in range(0,11):
if x==y:
print(x+y)
else:
print(x-y)
Q39.
p=30
for c in range(0,p):
if c%4==0:
print(c*4)
elif c%5==0:
print(c+3)
else:
print(c+10)

Q40.
Y=int(input("Enter 1 or 10: "))
if Y==10:
for Y in range(1,11):
print(Y)
else:
for m in range(5,0,-1):
print("thank you")

Q41.
def checkval():
x=int(input("Enter a number"))
if x%2==0:
print(x,"is even")
elif x>0:
print (x,"should be positive")
else:
print (x,"is odd")

Q42.
def result_even():
x=int(input("Enter a number"))
if (x%2==0):
print("Even number")
else:
print("Odd number")
even()

Q43.
m="SCHOOLbbbbCOM"

Q44.

Q45.
(ii)30#40#50#

Variable Max value Min value


FROM 3 1
TO 4 2
Q46.
As it is an infinite loop therefore the output will be "a" infinite times with
space between each "a"

Q47.
Output:1#
1#
1#
2#
1#
2#
3#

Q48.

Q49.
(ii)30#40#70#
(iv)35#40#60#

Variable Max value Min value


first 8 3
second 9 4
third 11 6

Q50.
i=0,1,2,3
L=[0.0,0.5,1.0,1.5]

Q51.
Y=0,1,2,3,4

# NOTE

int() gives zero when no argument is passed.

Possible outputs: 0:0


0:1
0:2
0:3
0:4
(ii) 0:3
(iii)0:0

Q52.
1st print statement: 6
2nd print statement: [2,3,4,4.5,5,6]

Q53.
Moves[2]=Moves[2]+22
Queen=[11,22,33,44]

=> Moves[2]=55
=> Queen=[11,22,55,44]
Moves=[11,22,55,44]

L=4
i=0,1,2,3

Queen[3] # 11
Queen[2] # 22
Queen[1] # 55
Queen[0] # 44

44 # 11
55 # 22
22 # 55
11 # 44

Q54.
(a) X is now:50

Q55.
End=3,4
Variable Max value Min value
End 4 3

Begin=1,2,3, when End=3


Begin=1,2,3,4, when End=4

(i)INDIGO&BLUE&GREEN&

Q56.
L=14
ntext="wELCOME!!pYTHON"

Q57.
200 # 100
200 # 200

Q58.
"fUN#pYTHONn#."

Q59.
15,16,17,18,19,20,21,22,23,24,25

#2nd print statement

115,116,117,118,119,120,121,122,123,124,125

#3rd print statement

85,84,83,82,81,80,79,78,77,76,75

#4th print statement

1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500

(i) 15 122 84 2500


(ii) 21 120 76 1500

Q60.
Tuple

Q61.
length of tuple is 3

Q62.
Hello
WorldWorldWorldWorldWorld

Q63.
st= Hello how are you
st1= H*ll* h*w *r* y**
Q64.
(a)

{'salary':12000,'name':"Mahesh",'grade':"E1"}

(b)
["violet","indigo","orange","red"]

Q65.
"hAPPYbIRTHDAY"

Q66.
Output: 8

Q67.
n=10
i=0,1,2,3,4,5,6,7,8,9

m="vELCcME#Kk"

Q68.
BEGIN=1,2,3
LAST=2,3,4

(i)30-40-50-

Variable Max value Min value


BEGIN 3 1
LAST 4 2

Q69.

newstr="STUDENT"

Q70.

def Bubble_sort(Ar):
for i in range(0,len(Ar)):
k=i
for j in range(i+1,len(Ar)):
if Ar[j]<Ar[k]:
k=j
Ar[i],Ar[k]=Ar[k],Ar[i]
print(Ar)

Q71.

def count():
file=open("[Link]","r")
h=0
w=0
for line in [Link]():
if line[0].lower()=="h":
h+=1
elif line[0].lower()=="w":
w+=1
print("No. of lines starting with 'w' are:",w,"\n","No. of lines starting with
'h' are:",h)
[Link]()
count()
Q72.

def cntwords():
file=open("[Link]","r")
words=0
for i in file:
if [Link]():
words+=1
print("No. of words in the file are:",words)
[Link]()

Q77.

def sm(lst):
sum,mean=0,0
for i in lst:
sum+=i
mean+=(i/len(lst))
print("Sum of all numbers in the list is:",sum,"\n","Mean of all numbers in the
list is:",mean)

Q78.

def Linear_search(lst,n):
if n in lst:
print("It is present.")
else:
print("It is not present.")
Q79

def shift(lst,num):
outlist=[]
for item in range(len(lst)-num,len(lst)):
[Link](lst[item])
for item in range(0,len(lst)-num):
[Link](lst[item])
print(outlist)

Q80.

def shift2(lst,n):
k=len(lst)-1
for i in range(n):
y=lst[0]
for i in range(k):
lst[i]=lst[i+1]
lst[k]=y
print(lst)

Q81.
def freq(lst):
lst1=[]
for i in lst:
if i not in lst1:
[Link](i)
for j in lst:
print("The count for",j,"is",[Link](j))
Q82.
def COUNT_AND():
f=open("[Link]","r")
data=[Link]().lower().split()
count=0
for word in data:
if word=="and" or word=="&":
count+=1
print("And/and/AND occurs",count,"times.")
[Link]()

Q83.

def DISPLAYWORDS(): # if we want to account for all occurences of words starting


with
f=open("[Link]","r") # t even if it is repeated
data=[Link]().lower().split()
count=0
for words in data:
if words[0]=="t":
count+=1
print(count)
[Link]()

Q86.

def ch2():
f=open("[Link]","r")
data=[Link]().split()
for words in data:
if len(words)==2:
print(words,end=" ")
[Link]()

Q87.

def COUNT():
f=open("[Link]","r")
data=[Link]().lower().replace(","," ").replace("."," ").split()
print(data)
count=0
for words in data:
if words=="catholic" or words=="mother":
count+=1
print("Count of Catholic,mother is",count)
[Link]()

You might also like