Python Internals PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Written test 1

Section 1 rememberns

1. Define tokens ?
A ] write a note on different types of tokens ?
B] list the difference between input () and raw input() ?
(OR)
2. A] List the rules for an identifiers ?
B] write the syntax for if – elif – else Construct

Section 2 learning

3. A] write a python programming to find if a student has obtained Past class , second class , first class , fail
based on the percentage using if – elif – else Construct ?

B] rewrite the following code by correcting the errors.

Program :- a=input(“enter a number”)

b=Int{input (enter another number)}

If a>=b;

Print (“first number is greater”)

else:

Print (“second number is greater” )

(OR)

4. A] read the name , age and salary of a person and display it with a appropriate message?
B] convert the following while loop into for loop using range () , and write the output ?
Program :- check = 4
While (check <= 8):
Print (check * 10)
Check += 2
Section 3 application
5. Salara as drawn a triangle but does not know it’s type she as measurement of all size and his wondering
to know weather or is an equivalent , isosceles , scalene triangle . Write a program for the same in python
to find the type of triangle using if – elif – else .

Hint :- #equivalent triangle = all sides are equal

# isosceles = two sides are equal

# scalene = all sides are equal

Section 4 analysis

Write the output for the following

6. A] program :- y= 2

for b in range (3,15,4):

Print(“assessment”)

b=b+2

y=y+3
B] program :- x =10

y=1

while x>y

x =x-4

y=y+3

Print(x)

(OR)

7. A] Program :- i=0
While I<5
Print(i)
i+=1
if i==3:
Break
else:
Print(“hello”)

B] program:- a=9
b=2
While i<5
if (4=5) && (9<=10):
Print (“hello”)
else:
print (“bye”)
if =2
else:
Print (“quit”)
Written test 2

Section 1 remembernce

1. Define and write examples for each of the following


A] tuple , set
(OR)
B] list , dictionary
Section 2 understanding

2. A] Correct and rewrite the following python code


➢ word =input(input a word to reverse)
for char in range (len (word),-3,-1)
Print (char [word] , end=” “)

➢ For the given tuple find the maximum and minimum element by using max () and min() function .

➢ Correct and rewrite the following python code:-

Setx = set (“green”, “blue”)

Sety = set(“blue”,” yellow”)

Print(“orginal set elements:. “)

Print(setx)

Print(sety)

Print (intersection of 2 side sets: “ )

Setz=setx | set y

Print(setz)

(OR)
B] correct and rewrite the following python code
➢ list1 = [physics , chemistry , 2000,2001]
Print(list1)
delete [list(1)]
Print(list1)

➢ Display an integer list using for loop.

➢ Using remove () method remove 2 elements from the list by writing a python code

Section 3 application

3. A] write a python program by using insert () , extend() , pop() , index() , and index() method on a list.

(OR)

B] write a python program on dictionary datatype using update() , pop () , pop item() , len() , and
clear() methods.
Section 4 analysis

4. A] Write the output for the following python code


➢ Print (“{ } and{ } birth are best friends “. Format(“apple”,” banana”))
Print (“{1} and{0 } are best players “. Format(“Sachin”,” Virat”))
Print (“{ } ,{ } , { } “. Format(a=”grapes” , b=”apple”, c=” banana”))

➢ String_one=” sun”
String_two=” moon”
If string_one ==string_two:
Print(“born strings are equal”)
elif string_one < string_two:
print(“first string is greater than second string”)
else:
Print(“first string is less than second string”)

➢ List1=[10,40,30,40,10,10,10,40,50
List2=[“cat”,” bat ” , ” mat” , ” cat” , ”pet ”]
Print(“count of cat is = “, list2 .count(‘cat’))
Print(“count of 10 is = “, list1 .count(‘10’))
List1. Sort()
Print (list1)
List3=list1. Copy()
List3.append(70)
List3.append(85)
Print(“List3: “ ,+List3)
(OR)

B]Write the output for the following python code

➢ String=” computer science and engineering department”


list=string. Split()
Print(list1)

➢ List1=[2,3.,7,5,10,17,12,4,1,13]
For i in list:
If i%2==0:
Print(i)
List1=[1,2,4,6]
List2.append(List1)
Print(List2)
List4=[2,3,6]
List4[0] , List[1] =List[1] , List[0]
Print(List4)

➢ Dictionary={‘A’:'computer’,’B’:'for ’,'C’:'science’}
Print(dictionary. Keys())
Print(dictionary. Items ())
salary = {“raj”:5000 , “ram”:60000,”vijay”:70000}
list1=salary.values()
Print(sum (list1)
Written test 3

Section 1 remembernce

1. List any 3 Built-in function along with an examples and write a code for the same in a program.
(OR)
2. List all function used in files and write a program using file functions
Section 2 understanding
3. A]Write a note on generator function and also write a code using the same.
(OR)
B] List the common exceptions used while handling errors

4. A] write an example for the following :-


•lambda function.
• recession function
B] list the different types of function argument and explain any 2 along with example.
Section 3 application

5. Write a program in python by applying suitable constructs using modular approach.


• Fibonacci series
• factorial of a number
(OR)
For the above program use the package concepts and write code for the same.
Section 4 analysis

6. Analysis the given code and write the output for the same .

Program:- 1 def test (n):

return n*n

def getsquare (n):

for i in range (n):

yield test (i)

sq=getsquare (10)

For i in sq:

Print(i)

Program:- 2. Import math

def print _till_zero(n):

If (n==0):

return

Print(n)

n=n-1

Print_till_zero(n)

Print_till_zero(8)
Program :-3 tables=[lambda x=x:x*10 for x in range (1:11)]

for table in tables :

print (table())

(OR)

Program :- 4. def check(n):

x =int(n)%2

if x==0:

Print(“the number is even “)

else :

Print(“the number is odd”)

number =input(“enter a number”)

check(number)

Program:-5 import math

def compute (count):

i=0

sum=0

for I in range (count):

x = int(input(“enter an integer : “))

sum=sum+x

avg=sum/count

return avg

Program :-6 import math

def compute (number):

if ((number%5==0 ) and(number%7==0)):

print (number ,” is a mirror multiple of both 5 and 7”)

else :

Print (number,” is not a multiple of both 5 and 7”)

number=int (input (“enter an integer: “))

compute(number)
Skill test 1

Write any two questions

1. Write a python program using comparison , relational , Boolean , bitwise and string operators .
(OR)
2. A] Write a python Program using if – elif - else Construct.
B] write a python program using for loop Construct.

3. A] write a python program using tuple and use built-in function.


B] write a python program using list and use built-in function
(OR)
4. A] write a python Program using set and use built-in function
B] write a python program using dictionary and use built-in function.

➢ Algorithm for each program.


➢ Write and explain type of Construct used in the program.
➢ Write the program and execute it.
➢ Find errors and debug
➢ 1-7 activities to be submitted
Skill test 2

Write any two questions

1. A] write a python program using lambda function


B] write a python Program using generator function
(OR)
2. A] write a modular program in python
B] write a package program in python

3. Write a python program using try – except – else – finally Construct for catching exceptions
(OR)
4. A] write a python program using numpy for solving basic arithmetic in arrays.
B] write a python program using pandas using series.

➢ Algorithm for each program.


➢ Write and explain type of Construct used in the program.
➢ Write the program and execute it.
➢ Find errors and debug.
➢ 6-13 activities to be submitted.

You might also like