100 Networking Questions


Basic Python Programming

  1. Write a Python program to reverse a string. (I have also added code for reverse a list)
#Reverse a string
a="Hello"
try:
    print(a[::-1])
    #Reverse a list
    b=[1,'a',"Suchi"]
    print(b[::-1])
    print(b[2])
    c=b[2]
    print(c[::-1])
except Exception as e:
    print("Error Found"+e)

Reasoning:

  • [::-1] is Python slicing syntax:
    • : refers to the entire sequence.
    • -1 specifies the step (reverse direction).
  • This avoids using loops, making the program concise and efficient.

2. Implement a function to check if a number is prime.
num=23
if num<2:
    print("Not Prime")
for i in range(2,int(num**0.5)+1):
    if num%i==0:
        print("Not Prime")
print(num," is Prime ")

Reasoning:

  • A prime number is only divisible by 1 and itself.
  • Checking divisors up to the square root of n reduces time complexity to O(√n).

3. Write a program to calculate the factorial of a number using recursion.
number = 90
fact = 1
for i in range(1, number + 1):  # Loop from 1 to number (inclusive)
    fact = fact * i  # Multiply each i to fact
print("Factorial of ", number, " is ", fact)  # Display the result

Reasoning:

  • The factorial of n is n * (n-1)!.
  • The base case ensures the recursion stops when n reaches 0 or 1.

4. Create a program to find the GCD (Greatest Common Divisor) of two numbers.
def gcd(a, b):
    while b:  # Use the Euclidean algorithm
        a, b = b, a % b
    return a

# Example usage
num1, num2 = 56, 98
print(f"GCD of {num1} and {num2}:", gcd(num1, num2))

Reasoning:

  • The Euclidean algorithm works by repeatedly replacing the larger number with its remainder when divided by the smaller number.
  • When the remainder becomes 0, the other number is the GCD.
5. Write a Python program to convert a decimal number to binary.
def decimal_to_binary(n):
    return bin(n)[2:]  # Use Python's built-in bin() function and remove the '0b' prefix

# Example usage
number = 42
print(f"Binary representation of {number}:", decimal_to_binary(number))

Reasoning:

  • The bin() function converts a decimal number to its binary representation as a string prefixed with 0b.
  • Slicing off the prefix gives the pure binary format.
6. Implement a program to check if a string is a palindrome.
#palindrome string
a="MadaM"
b=a[::-1]
print("value of a and b are: ",a,b)
if a==b:
    print("Palindrome")
else:
    print("Not Palindrome")

Reasoning:

  • A palindrome reads the same forward and backward.
7. Write a program to generate the Fibonacci sequence up to n terms.

#Fibonacci

seq=[0,1]

num=10

for num in range(2,num):

    seq.append(seq[-1]+seq[-2])

print(seq)

Reasoning:

  • The Fibonacci sequence starts with 0 and 1, with each subsequent term being the sum of the previous two.
  • Using a loop and list ensures clarity and efficiency.
8. Create a program to find the largest and smallest numbers in a list.
#largest and smallest number in a list
a=[1,2,90,76,3,0]
print(min(a))
print(max(a))

#without using builtin function :
mini=a[0]
maxi=a[0]
for num in a:
    if num<mini:
        mini=num
    if num>maxi:
        maxi=num
print(mini,maxi)

Reasoning:

  • Python's min() and max() functions efficiently find the smallest and largest elements in a list.
9. Write a Python program to count the frequency of each character in a string.
#freq of each character
from collections import Counter
string="Nokia"
print(dict(Counter(string)))

Reasoning:

  • The Counter class from the collections module efficiently counts occurrences of elements in a string.
10. Implement a function to check if two strings are anagrams.
#anagrams
a="mena"
b="name"
print(sorted(a.lower())==sorted(b.lower()))

Reasoning:

  • Anagrams contain the same characters in different orders.
  • Converting to lowercase and sorting ensures a case-insensitive comparison.

Data Structures

  1. Write a program to implement a stack using a list.
  2. Implement a queue using a list in Python.
  3. Create a Python program to perform binary search on a sorted list.
  4. Write a program to find the sum of elements in a matrix.
  5. Implement a program to transpose a matrix.
  6. Write a Python program to find the maximum depth of a binary tree.
  7. Implement a function to perform in-order traversal of a binary tree.
  8. Write a program to merge two sorted linked lists.
  9. Implement a function to detect a cycle in a linked list.
  10. Create a Python program to sort a list using the merge sort algorithm.

Algorithms

  1. Write a Python program to implement the bubble sort algorithm.
  2. Implement the quicksort algorithm in Python.
  3. Write a program to find the shortest path in a graph using Dijkstra’s algorithm.
  4. Create a Python program to implement the Knapsack problem.
  5. Implement a function to find all subsets of a given set.
  6. Write a program to find the longest common subsequence of two strings.
  7. Implement a function to calculate the edit distance (Levenshtein distance) between two strings.
  8. Write a program to solve the N-Queens problem.
  9. Implement a function to find the minimum spanning tree of a graph using Kruskal’s algorithm.
  10. Write a program to perform depth-first search (DFS) and breadth-first search (BFS) on a graph.

Networking and Automation

  1. Write a program to check if a specific port on a server is open.
  2. Implement a script to ping a list of IP addresses and display the reachable ones.
  3. Write a program to fetch the MAC address of a device using Python.
  4. Create a Python script to establish an SSH connection and execute a command on a remote server.
  5. Write a program to simulate a simple DHCP server using Python.
  6. Implement a program to parse and display OSPF or BGP configuration from a router.
  7. Write a script to monitor network traffic using Python (e.g., with scapy).
  8. Create a program to check if a specific website is reachable (HTTP status).
  9. Implement a script to retrieve and parse SNMP data from a network device.
  10. Write a Python program to generate random passwords for network devices.

String Manipulation

  1. Write a program to remove duplicates from a string.
  2. Implement a function to find all permutations of a string.
  3. Write a Python program to count the number of vowels and consonants in a string.
  4. Create a program to find the first non-repeating character in a string.
  5. Implement a program to reverse words in a given sentence.
  6. Write a function to check if a string contains only unique characters.
  7. Implement a Python program to convert camel case to snake case and vice versa.
  8. Write a program to find the longest palindrome substring in a string.
  9. Implement a function to compress a string using the counts of repeated characters.
  10. Write a Python program to sort a string alphabetically.

File Handling

  1. Write a program to read a file and count the number of lines and words.
  2. Create a script to merge two files into one.
  3. Write a Python program to find duplicate lines in a file.
  4. Implement a function to search for a specific string in a file.
  5. Write a script to read and parse a CSV file in Python.
  6. Create a program to write a list of dictionaries to a JSON file.
  7. Write a script to monitor changes in a log file in real-time.
  8. Implement a program to count the number of occurrences of each word in a file.
  9. Write a script to find and replace a string in a text file.
  10. Create a program to split a large file into smaller chunks.

Mathematical Problems

  1. Write a program to check if a number is an Armstrong number.
  2. Implement a function to find the LCM (Least Common Multiple) of two numbers.
  3. Write a program to find the sum of the digits of a number.
  4. Create a program to generate all prime numbers up to n.
  5. Write a program to check if a number is a perfect square.
  6. Implement a Python program to calculate the power of a number without using **.
  7. Write a program to find the roots of a quadratic equation.
  8. Implement a Python program to calculate the area of different shapes (circle, triangle, rectangle).
  9. Write a program to convert Roman numerals to integers.
  10. Create a Python program to find the sum of all prime factors of a number.

Advanced Topics

  1. Write a Python script to create and manipulate threads.
  2. Implement a program to demonstrate inter-thread communication.
  3. Create a Python program to implement a producer-consumer problem using threads.
  4. Write a program to serialize and deserialize Python objects using pickle.
  5. Implement a Python program to schedule tasks using schedule or apscheduler.
  6. Write a program to simulate a REST API client in Python.
  7. Create a Python script to parse and display XML data.
  8. Write a program to solve the Tower of Hanoi problem.
  9. Implement a Python script to encrypt and decrypt data using the cryptography library.
  10. Write a Python program to create a simple chatbot using NLP libraries.

Machine Learning and Data

  1. Write a program to perform linear regression using Python.
  2. Create a script to read and visualize data using matplotlib.
  3. Write a program to cluster data using the K-means algorithm.
  4. Implement a script to process and clean raw data using pandas.
  5. Write a program to predict house prices using a sample dataset.
  6. Create a Python script to analyze text sentiment using TextBlob.
  7. Write a program to perform image classification using a pre-trained model (e.g., ResNet).
  8. Implement a Python script to scrape data from a website.
  9. Write a program to calculate the confusion matrix for a classification model.
  10. Create a Python script to automate Excel operations using openpyxl.

Miscellaneous

  1. Write a program to simulate a simple calculator.
  2. Implement a function to check if a number is a power of two.
  3. Write a Python script to generate a QR code for a given URL.
  4. Create a program to display the current weather using an API.
  5. Implement a script to fetch emails from an inbox using IMAP.
  6. Write a program to schedule and send emails automatically using Python.
  7. Create a program to scrape trending topics from Twitter using tweepy.
  8. Write a script to compress and decompress files using Python.
  9. Implement a program to generate and validate a UUID.
  10. Create a Python program to simulate a simple game like Tic-Tac-Toe or Hangman.
  11. Fetch only all elements of a nested list to another list. 
a = [[1,2,3], 4, 5, [1,7], [10,20,30]] # Define the initial nested list 'a' 

result = [] # Initialize an empty list 'result' to store the extracted elements 

for element in a: # Iterate over each element in the list 'a' 
    if isinstance(element, list): # Check if the current element is a list 
        result.extend(element) # If it is a list, extend 'result' with the elements of the current list 
    else: # If the current element is not a list 
        result.append(element) # Append the current element to 'result' 

print(result) # Print the resulting list 'result'

Comments

Popular posts from this blog

TCL Interview Programs

Python Interview Programs

-: Networking interview questions :-