SUBMITTED TO –ARPNA
SUBMITTED BY -MR. SWYAMSEVAK SIR
COURSE- B.sc (honours) Computer Science
EXAMINATION ROLL NO.-24029570023
ROLL NO.- 24/CS/07
Q1:Wap to find roots of a quadratic equation.
OUTPUT:
Q2:Wap to accept a number ‘n’ and
(a) check if ‘n” is prime.
(b) generate all prime no. till “n”
(c) generate first ‘n’ prime no.
this program may be done using functions
OUTPUT:
Q3:Wap to create a pyramid of character “*” and a reverse
pyramid.
OUTPUT:
Q4:Wap to accept a character and perform the following:
(a)print whether the character is a letter a numeric digit or a
special character.
(b) if the character is a letter, print whether the letter is
uppercase or lowercase.
(c) if the character is a numeric digit print its name in text.
OUTPUT:
Q5:Wap to perform the following on string:
(a) find the frequency of a character in a string.
(b) replace a character by another.
(c) remove the first occurrence of a character in a string.
(d) remove all occurrence of a character in a string.
OUTPUT:
Q6:Wap to swap first n character of two strings.
OUTPUT:
Q7: Write a function that accepts two strings and returns the
indices of all the occurrences of the second string in the first
string as a list. if the second
string is not present in the first string then it return-1.
OUTPUT:
Q8: Wap to create a list of the cubes of only the even integers
appearing in the input list (may have element of other type
also) using the following:
(a) “for” loop
(b) list comprehension
OUTPUT:
Q9: Wap to read a file and
(A) print total no. of characters, words and lines in the
file.
(B) calculate the frequency of each character in the file.
use a variable of dictionary type to maintain the count.
(C) print the words in reverse order.
(D) copy even lines of the file to a file named ‘file1’ and
odd lines to another file named ‘file 2’.
File 1: python.txt
Program:
OUTPUT:
File 2: python 2.txt
File 3: python 3.txt
Q10:Wap to define a class point with coordinates x and y as
attributes. create relevant methods and print the objects. also,
define a method distance to calculate the distance between
any two-point object.
OUTPUT:
Q11: Write a function that prints a dictionary where the keys
are numbers between 1 and 5 and the values are the cubes of
the keys.
OUTPUT:
Q12: Consider a tuple t1(1,2,5,7,9,2,4,6,8,10). WAP to
perform following operations:
(a) Print half the values of the tuple in one line and the
other half in the next line.
(b) Print another tuple whose values are even numbers
in the given tuple.
(c) Concatenate a tuple t2=(11,13,15) with t1.
(d) Return maximum and minimum value from this
tuple.
OUTPUT:
Q13: WAP to accept a name from a user. Raise and handle
appropriate exception if the text entered by the user contains
digit and/or special character.
OUTPUT: