Python

savitry.in
0

Basic Python Concepts.  (Click here for solved problems and explanations)

  1. Write a Python program to calculate the factorial of a number using recursion.
  2. How can you check if a given string is a palindrome? Write a program to demonstrate.
  3. Write a program to find the largest and smallest elements in a list without using built-in functions.
  4. Demonstrate how to swap two numbers in Python without using a temporary variable.
  5. Write a Python program to generate the Fibonacci sequence up to n terms.

Data Structures in Python

  1. Write a Python program to sort a list of dictionaries by a specific key.
  2. Demonstrate the use of a stack using a Python list with push, pop, and peek operations.
  3. Write a program to find duplicates in a list and print their frequency.
  4. Implement a queue using Python’s collections.deque module.
  5. Write a Python program to flatten a nested list.

String Manipulations

  1. Write a program to count the number of vowels and consonants in a given string.
  2. Demonstrate how to reverse a string while preserving the positions of special characters.
  3. Write a program to find all permutations of a given string.
  4. How can you check if two strings are anagrams of each other? Write a program to show this.
  5. Write a Python program to capitalize the first letter of each word in a string.

File Handling

  1. Write a program to count the number of lines, words, and characters in a text file.
  2. Demonstrate how to merge the contents of two files into a single file.
  3. Write a Python script to read a file and remove all the blank lines.
  4. Create a program to find and replace a word in a text file.
  5. Write a Python program to read a CSV file and calculate the average of numerical columns.

Error and Exception Handling

  1. Write a program to handle division by zero using try-except blocks.
  2. Demonstrate how to raise and handle custom exceptions in Python.
  3. Write a Python program to read a file and handle the FileNotFoundError gracefully.
  4. Create a program that validates user input and raises exceptions for invalid entries.
  5. Write a Python script that logs errors to a file instead of printing them to the console.

Intermediate Topics

  1. Write a Python program to implement a binary search algorithm.
  2. Demonstrate how to implement the bubble sort and quick sort algorithms in Python.
  3. Write a program to calculate the transpose of a matrix.
  4. Demonstrate how to create and use lambda functions in Python.
  5. Write a Python program to merge two dictionaries.

Real-World Applications

  1. Create a Python program that simulates a simple calculator with basic operations.
  2. Write a program to scrape the titles and links of blog posts from a webpage.
  3. Demonstrate how to send an email with attachments using Python.
  4. Write a program to create a basic to-do list application using Python.
  5. Create a Python script to automate the renaming of files in a directory.

Advanced Topics

  1. Write a Python program to implement a simple REST API using Flask.
  2. Create a Python script to analyze a dataset using pandas and matplotlib.
  3. Write a program to solve optimization problems using Python’s scipy library.
  4. Demonstrate how to create a chatbot using Python and the OpenAI API.
  5. Write a Python script to perform image recognition using TensorFlow.

Some other Assignment Questions

  1. Set Operations:
    What is the output of the following code snippet?

    nums = set([1, 1, 2, 3, 3, 3, 4, 4])
    print(len(nums))
    

    Hint: Sets only store unique elements.

  2. Dictionary Keys:
    What will be the output of this Python code?

    d = {"john": 40, "peter": 45}
    print(list(d.keys()))
    

    Hint: d.keys() returns the keys of a dictionary.

  3. Password Validation:
    Write a Python program to validate a user's password based on the following criteria:

    • At least 1 letter between [a-z].
    • At least 1 letter between [A-Z].
    • At least 1 number between [0-9].
    • At least 1 special character from [$#@].
    • Minimum password length: 6.
    • Maximum password length: 12.
  4. List Iteration:
    Write a program using a for loop to print all elements of a list along with their positions.
    Example input:

    a = [4, 7, 3, 2, 5, 9]
    
  5. Even Indexed Characters:
    Write a Python program to accept a string from the console and print the characters at even indexes.
    Example input: H1e2l3l4o5w6o7r8l9d
    Example output: Helloworld

  6. Reverse String:
    Write a Python program that accepts a string from the console and prints it in reverse order.
    Example input: rise to vote sir
    Example output: ris etov ot esir

  7. Character Frequency:
    Write a Python program to count and print the frequency of each character in a given string.
    Example input: abcdefgabc
    Example output:

    a,2  
    b,2  
    c,2  
    d,1  
    e,1  
    f,1  
    g,1  
    
  8. List Intersection:
    Write a program to find the intersection of two given lists:

    list1 = [1, 3, 6, 78, 35, 55]
    list2 = [12, 24, 35, 24, 88, 120, 155]
    
  9. Remove Duplicates:
    Write a Python program to remove duplicate values from the following list while preserving the original order:

    list_with_duplicates = [12, 24, 35, 24, 88, 120, 155, 88, 120, 155]
    
  10. Remove Specific Value:
    Using list comprehension, write a Python program to remove the value 24 from the following list:

    original_list = [12, 24, 35, 24, 88, 120, 155]
    
  11. Remove by Index:
    Using list comprehension, write a program to remove the elements at the 0th, 4th, and 5th indexes from the following list:

    original_list = [12, 24, 35, 70, 88, 120, 155]
    
  12. Filter Divisible Numbers:
    Write a Python program using list comprehension to remove numbers divisible by both 5 and 7 from the following list:

    original_list = [12, 24, 35, 70, 88, 120, 155]
    
  13. Random List Generation:
    Write a program to randomly generate a list with 5 numbers divisible by 5 and 7, within the range of 1 to 1000 (inclusive).

  14. Fraction Sum Calculation:
    Write a Python program to compute the sum of the series 1/2 + 2/3 + 3/4 + ... + n/(n+1) for a given n > 0.
    Example input: n = 5
    Example output: 3.55



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !