Friday, 30 August 2019

Assignments on Python Data Types


Revision  Python Data Types
1. List all data types and write one example of each type.
2.  What is the difference between mutable and immutable data type? Give examples of each. 
3. Which of the following is true?
    a)   All keywords in python are in lower case
    b)   All variable names are case sensitive  
4.  Identify valid variable names from the following:
My_string_1 , 1ststring , Id , id , True , class
5. Which of the following is not a keyword?
eval, string , str , id , type
6.  Which of the following is a valid assignment statement?
     a)   a ; b ; c = 10  20 30                 b) a_b_c = 10 , 20 , 30
c)   a, b, c = 10 , 20 , 30               d) a b c = 10 20 30
7. If x=2 , What will be the output of the following:
          a) print(“x”)                             b) print( ‘x’ )                                                  c) print(x)
          d) print (‘x’ + 2 )                      d) print(‘x +  2’)            
e) print(‘x’ * 2)                         f) print( x * 2 )
8. Pick the correct assignment statement from the following and Justify your answer:
a) school = ‘Hans
                  raj’
b) school = “Hans
                  raj”
c) school='''Hans
                  raj'''
9. Write the output produced by the following statements:
          a) print(‘You\tare\tyour\nchoices’)
          b) print(‘\‘How old are you ?\’, he asked’)
          c) print('"Don\'t\ttalk in the class"')
10. Given a=15,b=9,c=1, Evaluate the following:
a) a % 4 + ( 3 + b // 4 ) – 2 ** c * 3
b)  a < c and b < c or  not ( a > c )
c) a != b or a > b and c == 1
11. What is a comment? Identify the comments in the following code snippet:
          # function to calculate area of a rectangle
def area(l,b):     # function definition
                   return l*b
print('Area=' , area(2,3) )  # function call
12. Given quote = “focus and win 100%”. Write the output produced by the following:
          a) quote[ -1]         b) quote[1]           c) quote[ len(quote) – 4 : ]
          d) quote[ : len(quote) – 4 ]               e) quote [ 6 : -5 ]
          f) quote.upper()                                 g) quote.title()
          h) quote.find(‘us’)                             i) quote.find(‘n’,10)
13. Given one = [ 11 ,22 ,33 ] and two = [ 33 , 55 ]. Write the output produced by the following:
            a) print( one[len(one) - 2 ] )              b) print( sum(two) // len(two) )
          c) print( max(one) // 10 )                            d) print( max(one) – min(one) )
          e) print(one.count(1))                        f) print(one.count(11))
          g)  two[1]=44                                    h) one.extend(two)                                i) tuple(one)
              print(two)                                           print(one)
14. Given odd=(1,3,[5, 7] , 9). Write the output produced by the following:
          a) odd[1:]             b) del odd[1]        c) odd[2][0] = 9   d) del odd[2][0]
                                                                                                               print odd
15. Given even=(2,4,6) . Write the output produced by the following:
          a) even[0] = 100                                        b)  a = list(even)
                                                                                  even[0] = 100
                                                                                  print(even)
16. Which of the following statement are correct for a dictionary?
          a) Record = { ‘name’ : [‘hansraj’] , ‘address’ : ‘punjabi bagh’ }
b) Record = { ‘name’ : [‘hansraj’] , ‘address’ : [‘punjabi bagh’] }
c) Record = { [‘name’] : ‘hansraj’ , [‘address’] : ‘punjabi bagh’ }
d) Record = { ‘name’ : [‘hansraj’] , ‘address’ : ‘punjabi bagh’ }
e) Record = { ('school') : ['hansraj'] , ('address') : ['punjabi bagh'] }
f) Record = { ('school') : ('hansraj') , ('address') : ('punjabi bagh') }
g) Record = { 'school' : 'hansraj' , 'address' : 'punjabi bagh' }

17. Given details =  { ‘exam’ : ‘Term1’ , ‘start’ : 9 , ‘end’ : 12  }.
      What will be the output of the following:
          a) print ( details.get(‘exam’) )               b) details[‘exam’]
          c) del details[‘end’]                              d) details[‘exam’] = ‘Half Yearly’
                                                                                 print(details)


No comments:

Post a Comment