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

Python Discussed Question

Uploaded by

chandralega.0610
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Python Discussed Question

Uploaded by

chandralega.0610
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

VELAMMAL VIDHYASHRAM, PADAPPAI

COMPUTER SCIENCE
UNIT-1 PYTHON REVISION TOUR
Discussed Question

1. Find the invalid identifier from the form the following


a)name b)class c)section d)break

2. for a given declaration in python as

a=’WELCOME’ find the output of

print(a[1::2])

3. Which of the following is an incorrect logical operator in

python

a)not b)in c)or d)and

4. s1=’hello’

Which of the following statement will give an error?

a)print(s1[4]) b)s2=s1 c)s1=s1[4] d)s1[4]=’y’

5. Which of the following is the default charachter for the

newline parameter for print function while the print

function in python IdLE

a)\n b)\t c) ‘ d) ;

6. print(5+3**2/2)
a)9.5 b)32 c)8.0 d)82.0

7. Which of the following is not a tuple in python?

a)(1,2,3) b) (‘one’,’two’,’three’)

c) (10,) d) (‘one’)

8. which of the following is not a function of the random

Module in python?

a)randfloat() b)randint()

c) random() d) randrange()

9. which of the following is not a valid python string

Operation

a) ‘Welcome’+’10’ b) ‘Welcome’*10

c)’Welcome’*10.0 d) ‘10’+”Welcome”

10. T=(10,20,[30,40,50],60,70)

T[2][1]=100

Print(T)

(10,20,[30,100,50],60,70)

11. L=[10,20,30,40,50]

L=L+5

print(L)
TypeError: can only concatenate list (not "int") to list

12. D{'Tanish':90,'kevin':96,'Gangesh':92,'srini':95}

print('srini' in D,90 in, sep='#')

True#False

13. Nithesh has declared a tuple T in python on as following

(10,20,30) Now he wants to insert an element 40 after

three elements of I so that the tuple may contain

(10,20,30,40)

a) T=T+40 b) T=T+(40)
b) T=t+(40,) d) cant insert because tuple is
immutable

14. s="GOOD MORNING'

print(s.capitalize(),s.title(),end='!')

15. l=[]

for i in range(4):

l.append(2*i+1)

print(l[::-1])

a) [7,5,3,1] b) [9,7,5,3] c) [4,3,2,1]


c) [1,2,3,4]
16. D={}

t=('karthi','Shanth','Roshan','Mano')

for i in range(1,5):

D[1]=t[i-1]

print(D)

17. l1,l2=[10,15,20,25],[]

for i in range(len(l1)):

l2.insert(i,l1.pop())

print(l1,l2,sep='&')

18. import random

for N in range(2,5,2):

print(random.randrange(1,n),end='#')

a) 1#3#5# b)2#3#

C)1#4# d)1#3#

19. t=''

s='PYTHON 3.9'

for i in s:

if i.isdigit():
t=t+i

print(s,t,sep='*')

20. l=[2,6,9,10]

for i in range(len(l)):

if l[i]%2==0:

l[i]=l[i]*2

elif l[i]%3==0:

l[i]=l[i]*3

else:

l[i]=l[i]*5

for i in l:

print(i,end='#')

22. d={1:'ome',2:'tow',3:'three'}

l=[]

for k,v in d.items():

if v[0]==7:

l.append(k)
print(l)

23. write a program to input a number and print if it is odd

Or even

Answer:

num=int(input())

if num%2==0:

print('the number is even')

else:

print('the number is odd')

24. Write a program to print the given dtring in reverse

a=input()

print(a[::-1])

25. v=25

print(v,end='*')

v=50

print(v,end='!')

v*=2

print(v,end='!')

print(v)
26. s='UVW';l=[10,20,30];d={}

n=len(s)

for i in range (n):

d[l[i]]=s[i]

for k,v in d,items():

print(k,v,sep='4',end=',')

27. Write a program to calculate and print the roots of a

Quadertic eqution (ax^2+bx+c=0)

a=int(input(‘enter a:’))

b=int(input('enter b'))

c==int(input('enter c'))

root1=(-b+(b**2-4*a*c)**0.5)/(2*a)

rootn=(-b-(b**2-4*a*c)**0.5)/(2*a)

print(f'The positive root is{rootp} and negative root


is{rootn}')

28. l=[10.20]

l1=[30,40]

l2=[50,60]

l.append(l2)
print(l)

29. print the following

BB

CCC

DDDD

EEEEE

For i in range(65,70):

Print(chr(i)*(-65+i+1))

30. 10

99

888

7777

66666

answer for i in range(1,60):

for j in range(10,5,-1):

print(j,end='')

print()
31. for i in range(1,100,1):

if i%4==2:

print(i,'mod',4'=2')

convert to while loop

i=1

while i<100:

if i%4==2:

print(i,'mod',4'=2')

i+=1

32. x='abcdef'

i='a'

while i in x:

print(i,end='')

33. n=50

i=5

s=0

while i<n:

s+=i

i+=10
print('i'=,i)

print('sum=1',s)

34. x=12

For i in x:

Print(i)

35. x=’abcdef’

i=’i’

while i in x:

print(i,end=’’)

36. name any two random module name

Randrange()
Randint()

37. p=MY PROGRAM

i=0

while p[i]1='r':

l=random.randint(0,3)+5

print(p[l],'-')

i+=1
38. str1='sure'

str2='try it'

n1=10

n2=3

print(str1+str2)

print(str1*n2)

print(str1+n1)

print(str2*str1)

39. Write a program to check a string is palindrome

a=input()

b=a[::-1]

if b==a:

print('given string is palidram')

else:

print('not palidrome')

40. Write a program to eligble to vote

age=int(input())

if age>=18:

print('eligble')
else:

print('not eligble')

41. nav=['LEFT','FRONT','RIGHT','BACK']

num=random.randint(1,3)

navg=''

for c in range(num,1,-1):

navg=navg+nav[c]

print(navg)

42. Tiny individual units in python program is known as

A) token b) expression c)steatement d) comment

43. Which of the following operator cannot be used with

String

a) + b) * c) - d) none of these

44. Name the building mathematical function that is used to

Return square root of a number

a) SQRT() b) sqrt() c) sqt() sqte()

45. Write the output

A=8/2

B=8//3

print(A,B)
46. print(min(max9false,-3,-4),2,7))

47. Take a two list & write a program that return a lists only

element that are common between the two list(without

duplicates) in ascending order. Make sure your

program works on two list of different sizes

ex:

l1[1,1,2,3,5,8,13,21,34,55,89]

l2=[20,1,2,3,4,5,6,7,8,9,10,11,12,13]

The out put should be[1,2,3,5,8,13]

48. Write a void function that recavies a 4-digit no and

Calculates tha sum of the squres of each digit in the

Number.

sqnum=0

num=int(input())

for i in num:

sqnum+=int(i0**2)

print(sqnum)

49. stri=list('Test')
for i in range(len(str1)):

if i==3:

x=int(i)

x+=x-3

str[i]=x

elif str1[i].i.lower():

stri[i]=str1[i].upper()

else:

str1[i]=stri[i]*2

print(str1)

50. a=[1,2,3]

b=[5,6,7]

for i in range(1,3):

a[i-1]=a[i]+1

for i in range(1,3):

print(a[i],end='_')

for i in range(1,3):

b[i-1]=b[i]+1

for i in range(0,3):

print(s[i],end='#')
51. print(25//4+3**1**2*2)

52. Tday=”Focus from self-image to self-esteem”

x=Tday.split()

print(x[0],x[3],x[4])

print(Tday.captialize(),Tday.title())

53. Find the errors and rewrite the program.

num1,num2=10

while num1%num2=0

num1+=20

num2+=30

Else:

Print(‘hello’)

54. message=”Bring it on!!!”

print(message[ : :-2])

55. book_dict={‘title’:’you can win’ , ’copies’:15}

book_dict[‘author’]=’Shiv Khara’

book_dict[‘genre’]=’Motivation’

print(book_dict.items())
56. str=””

name=”9@Days”

for x in name:

if x in ‘aeiou’:

str=str+x.upper()

elif not x.isalnum():

str=str+”**”

elif is.digit():

pass

else:

str=str+x.lower()

print(str)

57. moves=[11,22,33,44]

Queen=moves

Moves[2]+=22

L=len(moves)

for i in range(L):

print(“Now @”,Queen[L-i-1],’#’,moves[i])
58. tuple1=([7,6],[4,4],[5,9],[3,4],[5,5],[6,2],[8,4])

Listy=list(tuple1)

New_list=[]

for elem in listy:

tot=0

for value in elem:

tot+=value

if elem.cpunt(value)==2:

New_list.append(value)

tot=0

else:

print(tuple(new_list))

59. print(2*7+2**3-2/5+3%4)

60. S=’GOOD MORNing’

Print(S.capitalize(),S.title(),S.lower(),end=’!’)

61. x=’IncredibleIndia’[-2:-7:-1]

print(x,x[2:-2],sep=’$’)
62. x,y=(1,2),(3,4)

y,x=x,y+(2,)

print(x,y)

63. from random import randint

vibgyor=[[‘V’,’Violet’,[‘I’,’Indigo’],[‘B’,’Blue’],[‘G’,’Green’],[‘Y’,’
Yellow],

[‘O’,’Orange’],[‘R’,’Red’]]

for I in range(3):

first=randint(0,1)

last=randint(1,2)+1

print(vibgyor[last-first],end=’:’)

64. L=[100,212,310]

print(L)

L.extend([33,52])

for I in range(len(L)):

if L[i]%10==0:

L[i]=L[i]/5
elif L%2==0:

L[i]=L[i]//10

else:

L[i]=L[i]%10

print(L)

65. S=’welcome2cs’

N=len(s)

M=’’

for i in range(0,n):

if S[i]>=’a’ and S[i]<=’m’:

M=M+S[i].upper()

elif S[i]>’n’ and S[i]<=’z’:

M=M+S[i-1]

elif S[i].isupper():

M=M+S[i].lower()

else:

M=M+’$’

Print(M)
66. i=0

while i<0:

i=i+1

if i==5:

break

print(i,end=’’)

67. for x in range(0,10,2):

print(x,’#’,end=’’)

68. disc={‘age1’:26, ’age2’:32, ‘age3’:40}

sum=0

for key in disc:

sum=sum+disc[key]

print(sum)

69. S=”PREboardcs*2024”

j=2

for I in S.split(‘*’):

k=i[ :j]
if k.isupper():

j=j+1

elif k.isdigit():

j=j+2

else:

j=j+3

print(s[j: :j])

70. Text=’Gmail@com’

Len=len(Text)

72. Write a program to print the sum of series,

S=1+x+x^2+x^3+…x^n.

73. Write a program to take a list of string and returns a


dictionary where the key are the letter from the list and the
values are the number of times the letter appears in the list.

ntext=’’

for i in range(0,Len):

if Text[i].isupper():

ntext=ntext+Text[i].lower()
elif Text[i].isalpha():

ntext=ntext+Text[i].upper()

else:

ntext=ntext+”b”

print(ntext)

71. word=”green vegetable”

print(word.find(‘g’,2))

print(word.find(‘tab’,2,15))

74. List=[2,4,6,8,10]

for i in range(1,5):

List[i-1]=List[i]

for i in range(0,5):

print(List[i],end=’ ’)

75. Write a program that takes a list of string as


argument and display the longest string from the list.

You might also like