All Python scripts I wrote for my college Assignment.
Questions:
-
Write a Program in Python to accept a String as Input and count the number of:
a. Vowels
b. Consonants
c. Digits
d. Special Characters present in the string. -
Write a program in Python to accept a String as Input and display all the characters present in the odd numbered positions.
-
WAP in Python to take the following data as input from the user:
a. Name
b. Age
c. Gender
d. Occupation
“Hi . You are years old. You are a . You work as a .”
This string has to be printed thrice, first using % formatting, then str.format() function and then finally using F-Strings. -
WAP in Python to ask the user for two strings, and print a new string where the first string is reversed, and the second string is converted to upper case.
Sample strings: “Pets“, “party”
Output: “steP PARTY”. Only use string slicing and + operators -
Write a Program in Python to take a set of characters as Input in a List and covert it to a String. For example:
Input: [‘P’, ‘L’, ‘U’, ‘E’]
Output: PLUE -
Write a Program to take a String as Input and convert it to a List. The string comprises of multiple words, whereas the generated list will comprise of the words present in the string. For example,
Input: Dot was The Impostor
Output: [“Dot”, “was”, “The”, “Impostor”] -
WAP in Python to create the Following Sets:
• U = {x:x is a natural number less than 50} #Universal Set
• A = {x:x is a natural number less than 20}
• B = {x:x is a natural number that is divisible by 4 and less than 50}
Perform the following operations:
i. A’
ii. B’
iii. A intersection B
iv. A Symmetric Difference B
v. A’ Symmetric Difference B’
vi. A-B
vii. B-A
viii. Verify the 2 De Morgan’s Laws
ix. Is A a Proper Subset of U? -
WAP in python to take a list of integers as input from the user, and sort it in ascending order using any one of the following sorting algorithms:
• Merge Sort
• Quick Sort
A user-defined function for each sorting algorithm is expected.
The user must be asked which algorithm he/she wishes to use in order to perform the sorting. -
WAP in Python to find out the n’th Term of the Fibonacci Series. You are supposed to write a recursive function fibo(n) in order to complete the above task.
This is going to be a Dynamic Programming implementation of the Fibonacci Series. Display the number of Recursive Calls being made.
Implement this program using Dictionaries. -
WAP in Python to simulate the working of:
a. Stack
b. Queue
using Python Lists. -
WAP in Python to take two integer sets (A and B) as input, and calculate the:
a. Jaccard Similarity [ len(A intersection B)/len(A union B) ]
b. Cosine Similarity [ dot(A, B)/((dot(A,A)**0.5)*(dot(B,B)**0.5)) ] -
WAP in Python to take a Dictionary as input and Invert it. By inversion, we mean swapping the keyvalue pair.
Please note that inversion is only possible if the values are unique. Display proper error messages if the values aren’t unique. -
WAP in Python to use dictionaries to count the word occurrences in a long string of text. The string has to be taken in as input.
-
WAP in Python to perform the following tasks:
a. Create a ‘Node’ class to represent Graph Vertices.
b. Create an ‘Edge’ class to represent Graph Edges.
c. Create a ‘DiGraph’ class to store and manipulate directed graphs. It should have the following functions:
i. Add nodes to the DiGraph;
ii. Add and remove edges from the DiGraph.
iii. Print nodes, and edges in a user readable format
d. Make a ‘Graph’ class to handle directed graphs which inherits from the ‘DiGraph’ class. In addition to all of the functionalities of the DiGraph class, it should support the following operation:
i. Creating a new ‘Graph’ object where all the edges are reversed and added to the DiGraph class.
e. Extend (a) and (b) to handle weighted graphs.
f. Traverse the Graph using BFS and DFS algorithm.
g. Implement Dijkstra’s Algorithm to solve the Single Source Shortest Path problem.
h. Implement Floyd-Warshall algorithm to compute the all pairs shortest path.
i. Implement Prim’s and Kruskal’s Algorithm to find the MST.