Assignment 1 - BAE SEM II
Assignment 1 - BAE SEM II
using Python
Students Name:
Roll Number:
Date: 23 – 01 - 2024
P1 Section B
Question 1: Write a Python program that takes user input for two numbers and performs
arithmetic operations (addition, subtraction, multiplication, and division). Ensure proper
error handling for invalid input.
Code:
Output:
Explanation:
Question 2: Create a Python program that uses a loop to generate a Fibonacci sequence of a
specified length. Allow the user to input the length of the sequence.
Code:
Output:
Explanation:
Question 3: Write a Python program that defines a function to check whether a given
number is prime or not. Test the function with user-input values.
Code:
Output:
Explanation:
Question 4: Develop a Python program that reads a string from the user and determines
whether it is a palindrome or not. Ignore spaces, punctuation, and letter casing.
Code:
Output:
Explanation:
Question 5: Implement a Python program that uses a dictionary to store information about
students (name, age, and grade). Allow users to add, update, and delete student records.
Code:
Output:
Explanation:
Question 6: Create a Python script that reads a file and counts the occurrences of each
word. Display the word frequency in descending order.
Code:
Output:
Explanation:
Question 7: Write a Python program that defines a function to calculate the factorial of a
given number. Test the function with user-input values.
Code:
Output:
Explanation:
Question 8: Develop a Python program that reads a list of numbers and separates them into
two lists: one with even numbers and another with odd numbers.
Code:
Output:
Explanation:
Question 9: Implement a Python program that reads a sentence from the user and replaces
all occurrences of a specified word with another word. Display the modified sentence.
Code:
Output:
Explanation:
Question 10: Create a Python program that defines a function to calculate the average of a
list of numbers. Test the function with both integer and floating-point values.
Code:
Output:
Explanation:
P2 Section B
Question 11: Write a Python program that reads a list of numbers and finds the maximum and
minimum values without using built-in functions like max() and min().
Code:
Output:
Explanation:
Question 12: Create a Python program that takes a string as input and counts the frequency of each
character. Display the results in alphabetical order.
Code:
Output:
Explanation:
Question 13: Develop a Python script that creates a list containing student grades. Calculate the
average grade for each student and display the results.
Code:
Output:
Explanation:
Question 14: Write a Python program that simulates a basic calculator with a menu. Allow the user
to perform arithmetic operations on two numbers until they choose to exit.
Code:
Output:
Explanation:
Question 15: Implement a Python program that reads a list of strings and sorts them based on the
length of each string in ascending order.
Code:
Output:
Explanation:
Question 16: Create a Python program that simulates a basic login system. Store usernames and
passwords in a dictionary and validate user credentials.
Code:
Output:
Explanation:
Question 17: Write a Python function that accepts a sentence and returns a dictionary containing the
count of each word in the sentence.
Code:
Output:
Explanation:
Question 18: Develop a Python program that reads a list of integers and removes duplicate elements.
Display the modified list without duplicates.
Code:
Output:
Explanation:
Question 19: Implement a Python program that reads a list of names and randomly selects a winner.
Prompt the user for the number of winners to select.
Code:
Output:
Explanation:
Question 20: Create a Python program that defines a recursive function to calculate the factorial of a
given number. Test the function with user-input values.
Code:
Output:
Explanation:
P3 Section B
Question 21: Write a Python program that prompts the user to enter a string and then prints the
string in reverse order.
Code:
Output:
Explanation:
Question 22: Create a Python program that reads a list of integers and identifies and prints the prime
numbers in the list.
Code:
Output:
Explanation:
Question 23: Implement a Python program that simulates a basic ATM. Allow users to check balance,
deposit, and withdraw money. Ensure proper validation for insufficient funds.
Code:
Output:
Explanation:
Question 24: Write a Python function that accepts a list of numbers and returns a new list with only
the unique elements (no duplicates).
Code:
Output:
Explanation:
Question 25: Develop a Python program that reads a sentence and counts the number of vowels
(both uppercase and lowercase). Display the count for each vowel.
Code:
Output:
Explanation:
Question 26: Create a Python program that generates a random password of a specified length.
Include a mix of uppercase letters, lowercase letters, numbers, and symbols.
Code:
Output:
Explanation:
Question 27: Write a Python program that reads a list of strings and concatenates them into a single
string. Add a space between each concatenated string.
Code:
Output:
Explanation:
Question 28: Implement a Python program that reads a list of names and groups them
alphabetically. Display the names in separate groups based on the first letter.
Code:
Output:
Explanation:
Question 29: Create a Python program that create two lists containing numeric data and their
weights. Calculate and display the weighted average of the dataset.
Code:
Output:
Explanation:
Question 30: Develop a Python program that reads a list of integers and finds the median value
(middle value) of the list.
Code:
Output:
Explanation:
P1 Section C
Question 31: Write a Python program that takes a sentence as input and counts the number of
words in it. Display the word count.
Code:
Output:
Explanation:
Question 32: Create a Python program that reads a list of numbers and calculates the sum of all the
even numbers and the sum of all the odd numbers.
Code:
Output:
Explanation:
Question 33: Implement a Python program that reads a string and checks if it is a pangram (contains
all the letters of the alphabet at least once).
Code:
Output:
Explanation:
Question 34: Write a Python function that accepts a list of numbers and returns a new list with only
the prime numbers.
Code:
Output:
Explanation:
Question 35: Develop a Python program that reads a list of strings and removes any duplicates,
maintaining the order of the original list.
Code:
Output:
Explanation:
Question 36: Create a Python program that creates a paragraph using triple quotes (‘’’ ’’’ or “”” “””)
of at least 20 words and counts the occurrences of each word in dictionary where word is key and
value is occurrence of that word. Ignore case sensitivity.
Code:
Output:
Explanation:
Question 37: Implement a Python program that simulates a basic inventory system. Allow users to
add, remove, and view items in the inventory.
Code:
Output:
Explanation:
Question 38: Write a Python program that reads a list of integers and checks if it is a palindrome
(reads the same forward and backward).
Code:
Output:
Explanation:
Question 39: Develop a Python program that reads a list of names and finds the longest name in the
list.
Code:
Output:
Explanation:
Question 40: Create a Python function that accepts two lists and returns a new list containing the
common elements between the two lists.
Code:
Output:
Explanation:
P2 Section C
Question 41: Write a Python program that reads a sentence and counts the occurrences of each
letter. Display the counts for each letter in alphabetical order.
Code:
Output:
Explanation:
Question 42: Create a Python program that reads a list of strings and finds the longest and shortest
strings in the list.
Code:
Output:
Explanation:
Question 43: Implement a Python program that reads a list of numbers and calculates the mean
(average) and median of the list.
Code:
Output:
Explanation:
Question 44: Write a Python program that takes a string as input and checks if it is a valid palindrome
sentence (ignoring spaces, punctuation, and letter casing).
Code:
Output:
Explanation:
Question 45: Develop a Python program that reads a list of words and sorts them based on the
number of vowels in each word.
Code:
Output:
Explanation:
Question 46: Create a Python program that simulates a basic quiz. Store a set of questions and
answers, allowing the user to answer each question and providing a score at the end.
Code:
Output:
Explanation:
Question 47: Write a Python function that accepts a string and returns a new string with each word
reversed.
Code:
Output:
Explanation:
Question 48: Implement a Python program that reads a list of numbers and determines if it forms an
arithmetic progression (AP). If yes, find the common difference.
Code:
Output:
Explanation:
Question 49: Develop a Python program that reads a list of strings and removes any leading and
trailing whitespaces from each string.
Code:
Output:
Explanation:
Question 50: Create a Python function that accepts a list of numbers and returns a new list with only
the numbers that are perfect squares.
Code:
Output:
Explanation:
P3 Section C
Question 51: Write a Python program that reads a list of strings and checks if each string is a
valid email address. Display the valid email addresses.
Code:
Output:
Explanation:
Question 52: Create a Python program that reads a list of integers and removes all duplicate
occurrences, leaving only the first occurrence of each number.
Code:
Output:
Explanation:
Question 53: Implement a Python program that reads a list of words and capitalizes the first
letter of each word.
Code:
Output:
Explanation:
Question 54: Write a Python program that creates a dictionary containing student names
and their scores. Determine and display the top three scoring students.
Code:
Output:
Explanation:
Question 55: Develop a Python program that reads a list of dates and sorts them in
chronological order.
Code:
Output:
Explanation:
Question 56: Create a Python program that generates a password based on user-specified
criteria, such as length and inclusion of uppercase letters, numbers, and symbols.
Code:
Output:
Explanation:
Question 57: Write a Python program that reads a list of numbers and checks if it forms a
geometric progression (GP). If yes, find the common ratio.
Code:
Output:
Explanation:
Question 58: Implement a Python program that reads a list of sentences and counts the
number of occurrences of each unique word across all sentences.
Code:
Output:
Explanation:
Question 59: Develop a Python program that reads a list of strings and checks if each string
is an anagram of a specified word. Display the anagrams.
Code:
Output:
Explanation:
Question 60: Create a Python function that accepts two strings and determines if they are
anagrams of each other.
Code:
Output:
Explanation:
P3 Section A
Question 61: Write a Python program that reads a list of sentences and counts the number of words
in each sentence. Display the results in a dictionary.
Code:
Output:
Explanation:
Question 62: Create a Python program that reads a list of numbers and replaces each negative
number with its absolute value.
Code:
Output:
Explanation:
Question 63: Implement a Python program that reads a list of strings and checks if each string is a
palindrome when considering only alphanumeric characters.
Code:
Output:
Explanation:
Question 64: Write a Python program that reads a list of dates and calculates the difference in days
between each consecutive pair of dates.
Code:
Output:
Explanation:
Question 65: Develop a Python program that reads a list of strings representing file names. Filter the
list to include only files with a specific extension.
Code:
Output:
Explanation:
Question 66: Create a Python program that reads a list of integers and finds the second-largest and
second-smallest numbers in the list.
Code:
Output:
Explanation:
Question 67: Write a Python program that reads a list of sentences and checks if each sentence ends
with proper punctuation (period, question mark, or exclamation mark).
Code:
Output:
Explanation:
Question 68: Implement a Python program that reads a list of strings and converts each string to title
case (first letter capitalized).
Code:
Output:
Explanation:
Question 69: Develop a Python program that reads a list of names and checks if each name is a valid
username (contains only alphanumeric characters and underscores).
Code:
Output:
Explanation:
Question 70: Create a Python function that accepts a string and returns the count of vowels and
consonants in the string.
Code:
Output:
Explanation: