Posts

Programming Assignment - 10

Programming Assignment - Week 10 Note: There could be optimised ways to solve the problem, but the goal here is to solve it effectively. The most intuitive solution has been provided for clarity. Programming Assignment 1 Question: Write a program that accepts the string para and a positive integer n as input. The program should print 1 if there is at least one word in para that occurs exactly n times, and 0 otherwise. Input Format: The input consists of two lines. The first line contains the string para , which is a sequence of space-separated words. The second line contains a positive integer n . Output Format: A single integer, either 1 or 0 . Print 1 if there is at least one word that occurs exactly n times. Print 0 otherwise. Example: Input: apple orange apple banana orange banana banana 2 Output: 1 Code: from collections impor...

Week - 10 Quiz Assignment

Quiz Week 10 : Assignment 10 1. What will be the output of the following Python code? s = "Hello, World!" print (s[7:12]) "World" "World!" "Worl" "orld" 2. Which string method would you use to remove all leading and trailing whitespace from a string in Python? strip() split() replace() join() 3. Given the string s = "PythonProgramming", what does s [::2] return? "PythonProgramming" "Pto rgamn" "PyonPormig" "PtoPormig" 4. Why are names often converted to lowercase and spaces removed when implementing the FLAMES game in Python? To increase game difficulty To ensure consistent character comparison Because uppercase letters are not supported in Python strings ...

Programming Assignment - 9

Programming Assignment - Week 9 Note: There could be optimised ways to solve the problem, but the goal here is to solve it effectively. The most intuitive solution has been provided for clarity. Programming Assignment 1 Question: Write a Python function that counts the number of vowels in a given string s . The function should return the number of vowels found, considering both uppercase and lowercase vowels. Input Format: The input consists of a single string s . Output Format: A single integer representing the count of vowels in the string. Example: Input: hello world Output: 3 Code: def count_vowels ( s ): vowels = { 'a' , 'e' , 'i' , 'o' , 'u' , 'A' , 'E' , 'I' , 'O' , 'U' } vowel_count = 0 for char in s : if char in vowels : vowel_count += 1 r...

The joy of computing using Python Week - 9

Quiz Week 9 : Assignment 9 1. ‘nltk.download()‘ function downloads necessary packages for the Natural Language Toolkit (NLTK) library? True False 2. Which of the following best defines a complete graph? A graph where every pair of distinct vertices is connected by a unique edge A graph with no edges A graph with a single vertex A graph with at least one loop 3. How many edges are there in a complete graph with 4 nodes? 6 8 12 16 4. Which Python library is most commonly used for working with graphs related to networks? Random Pandas NumPy NetworkX 5. Gephi is: A Python library for linear algebra A software for visualizing and analyzing large networks A tool for data cleaning and preprocessing A Python library for building statistical models ...

Programming Assignment - 8

Programming Assignment - Week 8 Note: There could be optimised ways to solve the problem, but the goal here is to solve it effectively. The most intuitive solution has been provided for clarity. Programming Assignment 1 Question: Write a Python function that takes an integer n followed by n lines of space-separated integers, where each line represents a tuple. The function should return the sum of the first elements of all tuples. Input Format: The first line contains a single integer n , which represents the number of tuples. The next n lines each contain two space-separated integers representing the values of the tuple. Output Format: A single integer representing the sum of the first elements of all tuples. Example: Input: 3 3 4 1 2 5 6 Output: 9 Code: def sum_of_first_elements (): # Read the number of tuples n = int ( input ()) # Initialize the sum ...

The joy of computing using Python Week - 8

Quiz Week 8: Assignment 8 1. Which of the following is a valid way to create a tuple in Python? t = [1, 2, 3] t = (1, 2, 3) t = {1, 2, 3} t = 1, 2, 3 2. Which of the following operations is valid on a tuple? t[1] = 4 t.append(4) t = t + (4,) del t[1] 3. What will the following code output? t = [1, 2, 3] print(type((t, t))) <class 'list'> <class 'set'> <class 'tuple'> Error 4. What is the primary purpose of the matplotlib.pyplot module in Python? To perform matrix operations. To handle file I/O operations. To generate and customize visualizations like plots and graphs. To manipulate and process images. 5. Which of the following statements is true about anagrams? Two strings of different lengths can be anagra...

Programming Assignment - 7

Programming Assignment - Week 7 Note: There could be optimised ways to solve the problem, but the goal here is to solve it effectively. The most intuitive solution has been provided for clarity. Week 7: Programming Assignment 1 Question: You are given a board game scenario with ladders and snakes. A player starts at a given position on the board, and you are provided with the result of a die roll. You need to determine whether the player lands on a ladder, a snake, or a normal block after moving. Write a Python function named move_player that takes four inputs: ladders : A list containing the indices of blocks with ladders. snakes : A list containing the indices of blocks with snakes. current_position : An integer representing the player's current position on the board. die_roll : An integer representing the result of a die roll. The function should return...