Posts

Showing posts from October, 2024

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