CLASS TEST 11-04-2019 PYTHON

CLASS TEST WRITE ANSWERS IN NOTEBOOK

Q-01. What is syntax error and runtime error?

Q-02. Rewrite the following code after removing errors :
    a=int(input('value")
    b=0
    for c in range(1,a,2)
          b+=c
    Print (c*3)
    Else
    print (c*)

Q-03. Which method is used to implement the following :
    1. To count the number of characters in the string.
    2. To change the first character of the string in capital letter.
    3. To check given character is a letter or a number.
    4. to change lower case to upper case letter.

Q-04. Differentiate between append() and extend() function with example.

Q-05. Write a function in python to print the Nth Fibonacci number. N is input by user.

Q-06. Write a program in python ton input a list of numbers from the user and display only those numbers which are divisible by 3 but not by 5.

Q-07. Write a statement in python to open a text file 'story.txt' so that new contents can be added at the end of it.

Q-08. Write a python function named countthe() in python to read the text file 'data.txt' and count the
     number of times 'the' occurs in the file.

Q-09.  What is the value of after initialiaze x,y,z:
     x=[1, 2, 3, 4, 5]
     y=[11, 12, 13, 14, 15]
     z=(21, 22, 23, 24, 25)
     (a) 3*x  , b)  x+y , (c)  
 x[::2] , d) x[1] , e) x[0], f) x[-1] (g) x[:] h) x[2:4] (i) x[1:4:2] (j) x[:2]   

Q-10. Find the output of the follwing :
   L=[100,900,300,400,500]
   START = 1
   SUM=0
   for c in range(START,4):
         SUM=SUM + L[C]
         print (C, '=', SUM)
         SUM = SUM + L[0] * 10
         print SUM

Q-11. def ChangeList():
        k=[]
        m=[]
        n=[]
        for i in range(1,10):
           k.append(i)
        for i in range(10,1,-2):
           m.append(i)
        for i in range(len(m)):
           n.append(m[i]+k[i])
        n.append(len(k) - len(m))
        print k,m.n
   # call function main program
   ChangeList()

Q-12. Suppose L=['abc',[6,7,8],3,'mouse']
          consider the above list and answer the following :
          a) L[3:]             b)  L[::2]          c) L[1:2]     d) L[3:]
Q-13.  Python is an interpreter language. ( True / False ) Give reason

Q-14. Python is case-insensitive language. ( True / False )

Q-15. Which character is used for comments in python program?

Q-16. A string is a sequence of character. ( True / False ) Give reason.

Q-17. Write two usage of '+' operator.

Q-18. What is the output of statement  : print (id(5))

Q-19. What is the difference between '/' and '//' operator.

Q-20. Find the output of the following :
           colors=['violet','indigo','blue','green','yellow','orange','red']
           del color[4]
           colors.remove('blue')
           colors.pop(3)
           print (colors)
Q-21.  Find the output :
word='green vegetables'
print(word.find('g',2))
print(word.find('veg',2))
print(word.find('tab',4,15))

Q-22.  Find the output :
str="GdgiseasyPythonforbeginners is easytolearn"
str2="easy"
print("The first occurrence of str2 is at :",str.find(str2 , 1))

print("The first occurrence of str2 is at :",str.rfind(str2 , 6))


0 Comments