Python 1 QP
Python 1 QP
Python 1 QP
Roll. Number: 62
Name: Anik Chakraborty
Email:chakrabortyanik01@gmail.com
Mobile:9432063408
Instructions:
On completion, mail the document to the E-mail ID from your personal email:
python@sxccal.edu
Please confirm with the receipt of the answer document with the teacher
before you leave MS-Teams.
Page 1 of 10
Gr-A:Marks=(2x25=50)
Answer:b)
Answer:c)
Answer:c)
Answer:c)
Answer:c)
Page 2 of 10
6) How do you create a variable with the floating number 2.8?
a) Both the other answers are correct
b) x = 2.8
c) x = float(2.8)
Answer:a)
7) What is the correct syntax to output the type of a variable or object in Python?
a) print(type(x))
b) print(typeof(x))
c) print(typeOf(x))
d) print(typeof x)
Answer:b)
Answer:c)
Answer:b)
Answer:b)
Page 3 of 10
11) Which method can be used to remove any whitespace from both the beginning and the end of
a string?
a) ptrim()
b) len()
c) strip()
d) trim()
Answer:c)
12) Which method can be used to return a string in upper case letters?
a) uppercase()
b) upperCase()
c) upper()
d) toUpperCase()
Answer:c)
Answer:a)
a) *
b) #
c) %
d) X
Answer:a)
Page 4 of 10
15) Which operator can be used to compare two values?
a) <>
b) ==
c) ><
d) =
Answer:b)
Answer:c)
Answer:c)
Answer:b)
Page 5 of 10
19) Which of these collections defines a DICTIONARY?
Answer:c)
a) DICTIONARY
b) TUPLE
c) LIST
d) SET
Answer:c)
a) TUPLE
b) LIST
c) SET
Answer:c)
a) if (x > y)
b) if x > y:
c) if x > y then:
Answer:b)
Page 6 of 10
23) How do you start writing a while loop in Python?
Answer:a)
a) for x in y:
b) for x > y:
c) for each x in y:
Answer:a)
a) return
b) exit
c) stop
d) break
Answer:d)
Page 7 of 10
Broad Questions:
Gr-B: Marks=(10x5=50)
Q.No.26.
Write algorithm to input 3 arbitrary numbers (a,b,c). Calculate and print (i) largest value, (ii)smallest
value and (iii) average value.
Q.No.27.
Write a program in Python to input any sentence from keyboard. Calculate and print(i)Number
vowels, (ii) number of consonants within that sentence.
Q.No.28.
Input 2 positive integers( say a,b). Write a program in Python to calculate and print (i) HCF of a,b
and (ii) LCM of a,b.
Q.No.29.
Write a program in Python to input (i) Input File Name(=file1), (ii) output file-1 name(file2), (iii)
output file-2 name(file3). Split the content of input file into 2(two) components and then transfer
two(2) components to 2 output files. The program should also display size of input file and 2 output
files.
Q.No.30.
Write a program in Python to input name of some RGB image file(e,g, image1.jpg). Do the following
operations on input image file : Convert the RGB pixels to Gray scale. Print both RGB image and also
Gray scale images on screen. Use numpy and matplotlib to do all the above.
27.a=input(‘Enter a string:’)
a=a.strip()
a=a.lower()
n=len(a)
v=0
Page 8 of 10
alp=0
for i in range n:
ch=a[i]
if(ord(ch>=97 and ord(ch)<=122):
alp+=1
if(ch==’a’ or ch==’e’ or ch==’i’ or ch==’o’ or ch==’u’):
v+=1
print(‘Number of vowels in the entered string is ‘,v)
print(‘Number of consonants in the entered string is ‘,(alp-v))
def lcm(a,b):
lc=a*b//hcf(a,b)
return lc
30.import numpy as np
import matplotlib.pyplot as plt
img1=input(‘Enter your Image Filename =’)
data1=plt.imread(img1)
Page 9 of 10
shape1=data1.shape
print(‘Shape of data1=’,shape1)
r,c,d=shape1[0],shape1[1],shape1[2]
print(‘r=’,r,’c=’,c,’d=’,d)
R,G,B=data1[:,:,0],data1[:,:,1],data1[:,:,2]
print(‘R=’,R)
print(‘G=’,G)
print(‘B=’,B)
gray=.2989*R+.587*G+.114*B
shape2=gray.shape
print(‘Shape of gray scale image=’,shape2)
print(‘gray=’,gray)
rows=3
column=4
#The RGB Image gets displayed
fig=plt.figure(figsize=(20,20))
fig.add_subplot(rows,columns,1)
plt.axis(‘off’)
plt.title(‘RGB Image’)
plt.imshow(data1)
#The GrayScale Image gets displayed
fig.add_subplot(rows,columns,2)
plt.axis(‘off’)
plt.title(‘GrayScale Image’)
plt.imshow(gray,cmap=’Greys’)
Page 10 of 10
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: