Posts

Programming Assignment - 12

Programming Assignment - Week 12 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 recursive function named collatz that accepts a positive integer n as an argument, where 1 < n ≤ 32,000 , and returns the number of times the Collatz function has to be applied repeatedly in order to first reach 1. The Collatz function is defined as follows: If n is even, divide n by 2. If n is odd, multiply n by 3 and add 1. The function should continue applying this process until n becomes 1, and return the number of steps taken. Input Format: A single integer n where 1 < n ≤ 32,000 . Output Format: A single integer representing the number of steps required for n to reach 1. Example: Input: 12 Output: 9 Code: def collatz ( n ): if n == 1 :...

The Joy of Computing using Python Week 12 - Quiz Assignment

Week 12: Assignment 12 1. What is the key operation performed when the number n in the Collatz Conjecture is even? Add 1 Multiply by 3 and add 1 Divide by 2 Subtract 1 2. What happens to an odd number n in the Collatz Conjecture sequence? It is divided by 2 It remains unchanged It is replaced by n×3+1 It is replaced by n−1 3. What is the ultimate goal of the Collatz Conjecture sequence? Reach the number 0 Return to the starting number Reach the number 1 Cycle through odd numbers 4. Which of the following best describes the Collatz Conjecture? It has been proven for all natural numbers It remains an unsolved problem in mathematics It is a trivial problem with a simple solution It only applies to prime numbers 5. What is the main idea behind the PageRank algorithm...

Programming Assignment - 11

Programming Assignment - Week 11 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 a date in MM/DD/YYYY format as input and prints the date in DD-MM-YY format. The program should retain only the last two digits of the year, replace the forward slash / with a dash - , and swap the order of the month and date. Input Format: The input consists of a single line. The line contains a date string in MM/DD/YYYY format. Output Format: A single string in DD-MM-YY format. Print the date with the day and month swapped, the year truncated to the last two digits, and all separators replaced by dashes - . Example: Input:12/25/2024 Output: 25-12-24 Code: date_input = input () month , day , year = date_input .split( "/" ) year = year[-2:] formatted_date = f ...

Week - 11 Quiz Assignment

Week 11: Quiz Assignment 11 1. Which Python library is commonly used for automating web browsers for tasks like testing or web scraping? datetime selenium chrome webdriver 2. In Selenium, what is the purpose of the WebDriver (e.g., webdriver.Chrome())? To interact with databases To send HTTP requests To control a web browser programmatically To parse HTML and XML documents 3. Which method is used in Selenium to open a specific URL in the web browser? driver.open(url) driver.load(url) driver.navigate(url) driver.get(url) 4. In Selenium, how can you simulate pressing the Enter key in a text input field? input field.send keys(Keys.ENTER) input field.submit() input field.send keys(Keys.RETURN) input field.press(’Enter’) 5. How can you get the current local date and time in Python using th...

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...