Python Programs

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

Ryan International School, Chandigarh

Class XII

Subject: Computer Science

Programs based on Python

Note: Do this programs in your Notebook and write the output also.

Q1: WAP to input two numbers and display their sum and product.

Q2: WAP to compute the area of a circle.

Q3: Program to print the difference of two inputted numbers.

Q4: WAP to calculate income tax of an employee on the basis of basic

salary and total savings inputted by the user (using nested if…else

statement) as per given slabs:


· No tax for individuals with income less than ₹ 2.5 lakh
· 0% -5% tax with income ₹ 2.5 lakh to ₹ 5 lakh for different age
groups.
· 20% tax with income ₹ 5 lakh to ₹ 10 lakh
· Investments up to ₹ 1.5 lakh under Sec 80 C can save up to ₹
45,000 in taxes.

Q5: WAP to print cubes of numbers in the range 10 to 18.

Q6: WAP to print square root of every alternate number.

Q7: WAP to find maximum, minimum and mean value from the list.

Q8: WAP to store students’ information like admission number, roll no,

name and marks in a dictionary, and display information on the

basis of admission number.

Q9: Write a function LShift (Arr,n) in python which accepts a list Arr of

numbers and where n is a numeric value by which all elements of

the list are shifted to the left Sample input Data of the list Arr=

[10,20,30,40,12,11], n=2

Output Arr= [30,40,12,11,10,20]


Q10: WAP for python function string_length () to calculate the length of

a string: ‘Hello World’.

Q11: WAP python function to get a string from s given string where all

occurrence of its first char have been changed to ‘ $ ‘, except the

first char itself.

Sample string: ‘restart’

Expected Result: ‘resta$t’

Q12: WAP to print floating numbers with no decimal places.

X= 3.1415926

Y= -12.9999

Q13: WAP to get the largest number from a list.

Q14: Write script to input two integers and find their LCM.

Q15: Which of the following is valid arithmetic operator in python:


a) // b) & c)? d) and

Q16: ABC chemicals Ltd. is a company that deals in manufacturing and

exporting of chemicals across the world and has hundreds of

employees on its roll. It wishes to computerize the process of

salary generation. Write a Python program to enter the name of

employees and their salaries as input and store

them in a dictionary and also represent the data as a Salary

Generation Report.

Q17: WAP to calculate the sum of the digits of a random three-digit

number.
Q18: Write the output of the following code:

Def test (a):

Def add (b):

nonlocal a

a+=1

return a + b

return add

func = test (5)

print (func(5))

Q19: consider the following function that takes two positive integer
parameters a

and b. Answer the following questions based on the code below:

def func1(a, b):

if a> 1:

if a % b == 0:

print (b, end= ‘ ‘)

func1(int(a/b), b)

else:

func1(a, b+ 1)
a) What will be printed by the function call func1(24,2)?
b) What will be printed by the function call func1(84,2)?
c) State in one line what func1() is trying to calculate.

Q20: X is a python programmer and has imported the module math.

From this math module, he wants to use the function sqrt() to

calculate the square root of n. but he has forgotten how to use a

function from imported module. Help X use the function sqrt().


Q21: Write a method in python to find and display the prime numbers

between 2 to N. Pass N as argument to the method.

Q22: Write a function file_long() that accepts a filename and reports the

file’s longest line.

Q23: What is the output of the following code fragment? Explain.

>>>out = open (“output.txt”, “w”)

>>>out = write (“hello, world! \n”)

>>>out = write (“how are you?”)

>>>out. close()

>>> open(“output.txt”).read()

Q24: What is the output of the code:

Note: We assume that file ‘test1.txt’ contains four lines of text

f1=open (“test1.txt”, ”r”)

size = len (f1. read () )

print( f1.read (5))

Q25: Write a method write1() in python to write multiple lines of text


contents into a text file’daynote.txt’.

Q26: Write a method in Python to read lines from a text file


“MYNOTES.TXT” and display those lines which start with the alphabet
‘K’.

Q27: Write definition of a method MSEARCH(STATES) to display all the

state names from a list of STATES which start with alphabet M.


Ex: In the list STATES contains: [“MP”, “UP”, “WB”,”MZ” etc)

******

You might also like