Programming With Python
Programming With Python
GE-GENERAL ELECTIVE
(Undergraduate courses)
University of Delhi
Practicals / Activities
I would want to convey my heartfelt gratitude to karan gupta sir, my mentor, for her invaluable
advice and assistance in completing my project. He was there to assist me every step of the way,
and her motivation is what enabled me to accomplish my task effectively. I would also like to
thank all of the other supporting personnel who assisted me by supplying the equipment that was
essential and vital, without which I would not have been able to perform efficiently on this project.
I am grateful to the college administration for providing me with such a significant chance. I
guarantee that this project was created entirely by me.
Practical 1:
WAP to find the roots of a quadratic equation
Output:
2. WAP to accept a number ‘n’ and
a. Check if ’n’ is prime
b. Generate all prime numbers till ‘n’
c. Generate first ‘n’ prime numbers
This program may be done using functions
This program defines three functions:
Upon running this program, it prompts the user to enter a number 'n', and then it performs the
tasks of checking if the number is prime, generating all prime numbers till 'n', and generating
the first 'n' prime numbers.
3. WAP to create a pyramid of the character ‘*’ and a reverse pyramid
This program uses a function print_pyramid(rows) that takes the number of rows
for the pyramid as input. It first prints the upper part of the pyramid with increasing '*'
count per row and then prints the lower part of the pyramid in reverse order.
You can change the rows variable to adjust the size of the pyramid. For instance,
setting rows = 5 will create a pyramid of 5 rows (and the same number of rows in the
reverse pyramid). Adjust the value of rows as desired to change the pyramid's size.
4.WAP that accepts a character and performs the following:
a. print whether the character is a letter or 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, prints its name in text (e.g., if input is 9, output is NINE)
This program defines a function character_analysis(char) that analyzes the given
character and performs the specified tasks:
cubes_of_even_integers_for_loop(input_list): Generates a list of cubes of even integers from the input list using a 'for'
loop.
cubes_of_even_integers_list_comprehension(input_list): Generates a list of cubes of even integers from the input list
using list comprehension.
9. WAP to read a file and
a. Print the total number 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 ‘File2’.
This program performs the following operations on a given file:
a. Counts the total number of characters, words, and lines in the file.
b. Calculates the frequency of each character in the file.
c. Prints the words in reverse order.
d. Copies even lines to 'File1.txt' and odd lines to 'File2.txt'.
10. Write a function that prints a dictionary where the keys are numbers
between 1 and 5 and the values are cubes of the keys.
11. 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
This program performs the following operations on the given tuple t1:
a. Prints half the values of the tuple in one line and the other half in the next line.
b. Prints another tuple whose values are even numbers in the given tuple.
c. Concatenates a tuple t2=(11,13,15) with t1.
d. Returns the maximum and minimum values from the concatenated tuple.
12. WAP to accept a name from a user. Raise and handle appropriate
exception(s) if the text entered by the user contains digits and/or special
characters.
This program defines a function check_name(name) that iterates through each character
of the entered name. If it encounters any character that is not an alphabet or space, it
The try-except block handles this potential exception. If the entered name contains
only alphabets and spaces, it prints the validated name. Otherwise, it catches the