This documentation provides an overview of various coding challenges and their solutions. Each challenge is explained along with the approach taken to solve it.
- Challenge: Create a rangoli pattern using the alphabet.
- Solution: Generate a list of alphabets and form a symmetric pattern by concatenating them with hyphens.
- Challenge: Use the reduce function to multiply fractions.
- Solution: Use the
reducefunction from thefunctoolsmodule to multiply a list of fractions.
- Challenge: Determine if a given year is a leap year.
- Solution: Check if the year is divisible by 4 and not 100, or divisible by 400.
- Challenge: Find the second highest score in a list of scores.
- Solution: Sort the unique scores and select the second highest one.
- Challenge: Print a specific pattern using numbers.
- Solution: Use nested loops and mathematical operations to generate the required pattern.
- Challenge: Perform mathematical operations on large integers.
- Solution: Use Python's built-in
powfunction to handle large integer calculations.
- Challenge: Compute power and modular power of integers.
- Solution: Use the
powfunction with two and three arguments to compute the power and modular power.
- Challenge: Generate combinations with replacement using itertools.
- Solution: Use
itertools.combinations_with_replacementto generate and print combinations.
- Challenge: Generate combinations of a given length using itertools.
- Solution: Use
itertools.combinationsto generate and print combinations of varying lengths.
- Challenge: Find the symmetric difference between two sets.
- Solution: Use set operations to compute the symmetric difference and print the result.
- Challenge: Calculate the happiness score based on elements in sets A and B.
- Solution: Use set operations to count the number of elements in set A and subtract those in set B.
- Challenge: Calculate the average of unique elements in an array.
- Solution: Convert the array to a set and compute the average.
- Challenge: Generate permutations of a given length using itertools.
- Solution: Use
itertools.permutationsto generate and print permutations.
- Challenge: Use the Counter class to solve a problem involving item counts.
- Solution: Use
collections.Counterto count and manage item quantities.
- Challenge: Generate the Cartesian product of input iterables.
- Solution: Use
itertools.productto generate and print the Cartesian product.
- Challenge: Capitalize the first letter of each word in a string.
- Solution: Split the string by spaces, capitalize each word, and join them back.
- Challenge: Format a given integer into different bases.
- Solution: Use string formatting to convert and align integers in various bases.
- Challenge: Create a designer doormat pattern.
- Solution: Use loops and string operations to generate the required pattern.
- Challenge: Wrap a string into a paragraph of given width.
- Solution: Use string slicing and the
textwrapmodule to wrap the text.
- Challenge: Check various properties of a string (alphanumeric, alphabetical, digits, etc.).
- Solution: Use string methods like
isalnum,isalpha,isdigit, etc., to validate the string.
- Challenge: Count occurrences of a substring in a string.
- Solution: Use loops and slicing to find and count the occurrences of the substring.
- Challenge: Modify a character at a given index in a string.
- Solution: Convert the string to a list, modify the character, and join it back to a string.
- Challenge: Print a personalized greeting message.
- Solution: Concatenate strings with formatted placeholders.
- Challenge: Split a string by spaces and join with hyphens.
- Solution: Use
splitandjoinstring methods.
- Challenge: Swap the case of each character in a string.
- Solution: Use string methods to convert uppercase to lowercase and vice versa.
- Challenge: Compute the hash of a tuple.
- Solution: Convert a list of integers to a tuple and use the
hashfunction.
- Challenge: Perform various list operations based on user input.
- Solution: Use list methods like
insert,append,remove, etc., to manipulate the list.
- Challenge: Calculate the average percentage of marks for a student.
- Solution: Compute the average of a list of marks and format the result.
- Challenge: Find students with the second lowest grade.
- Solution: Sort the list of grades and extract the names with the second lowest grade.
- Challenge: Find the second highest score in a list.
- Solution: Sort the unique scores and select the second highest one.
- Challenge: Generate a list based on certain conditions.
- Solution: Use list comprehensions to generate the list based on given conditions.
- Challenge: Print numbers from 1 to n without spaces.
- Solution: Use a loop to concatenate and print the numbers.
- Challenge: Determine if a given year is a leap year.
- Solution: Check if the year is divisible by 4 and not 100, or divisible by 400.
- Challenge: Print squares of numbers from 0 to n-1.
- Solution: Use a loop to print the squares of the numbers.
- Challenge: Perform integer and float division.
- Solution: Use the division operator to compute and print the results.
- Challenge: Perform basic arithmetic operations.
- Solution: Use addition, subtraction, and multiplication operators.
- Challenge: Print different outputs based on conditions.
- Solution: Use if-else statements to handle various conditions.
- Challenge: Print "Hello, World!".
- Solution: Use the
printfunction to display the message.