New Python Lab Manual - Non CS Streams
New Python Lab Manual - Non CS Streams
COIMBATORE
RECORD WORK
Register Number :
Semester :
SNS COLLEGE OF TECHNOLOGY
Coimbatore
(An Autonomous Institution)
Name : …………………………………………………………
Register Number:
Certified that this is the bonafide record of work done by the above student for
23ITP102-PYTHON PROGRAMMING LAB during the academic year
……………. to ……………..
FACULTY SIGNATURE
PASTE YOUR EXERCISM OVERVIEW SCREENSHOT
Exercise No: 1
Date: __________
Hello World
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Hello World" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand what the exercise expects: modify the code to return
or print "Hello, World!".
7. Understand the given stub code: it is a basic function template that you need to complete.
8. Write your solution step-by-step: replace the pass with code that returns the string "Hello,
World!".
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully to identify what went
wrong (e.g., wrong string or missing return).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. Understand the problem: The task is to produce the exact string "Hello, World!".
2. Identify the function that needs to be implemented from the stub code.
• Modify the provided code so that it produces the string "Hello, World!".
If everything goes well, you will be ready to fetch your first real exercise.
Python Fundamentals
• Basic string output using print(). Example: print("Hello, World!") outputs the string to the
console.
• Function definitions with def keyword. Example: def hello_world(): return "Hello, World!"
defines a function that returns the string.
• Comments using #. Example: # This is a comment.
• Docstrings using triple quotes. Example: """This is a docstring.""" for multi-line documentation.
Paste/Write your Code
RUBRICS
Result
The "Hello World" exercise was implemented successfully. The program outputs the required string and
passes all tests. The basics of Python syntax were verified.
Exercise No: 2
Date: __________
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Guido's Gorgeous Lasagna" exercise
and click on it to open the exercise page.
4. Read the instructions carefully. Understand the story about cooking lasagna and the four
functions you need to implement (expected bake time, remaining bake time, preparation time,
and total time).
6. In the online editor, look at the left side where the stub code is provided (constants and empty
functions with pass).
7. Understand the given stub code: it gives you the structure and you need to fill in the
calculations.
8. Write your solution step-by-step: define the expected bake time constant, then implement each
function using simple arithmetic operations.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully to identify issues (e.g.,
wrong calculation or missing return value).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
2. Calculate remaining bake time by subtracting minutes already in the oven from the expected
bake time.
3. Calculate preparation time by multiplying the number of layers by 2 minutes per layer.
4. Calculate total time by adding preparation time and time spent in the oven.
You're going to write some code to help you cook a gorgeous lasagna from your favorite cookbook.
You have five tasks, all related to cooking your recipe.
Note
We have started the first function definition for you in the stub file, but you will need to write the
remaining function definitions yourself. You will also need to define any constants yourself. Read the
#TODO comment lines in the stub file carefully. Once you are done with a task, remove the TODO
comment.
Define the EXPECTED_BAKE_TIME constant that represents how many minutes the lasagna should
bake in the oven. According to your cookbook, the Lasagna should be in the oven for 40 minutes:
text
>>> print(EXPECTED_BAKE_TIME)
40
2. Calculate remaining bake time in minutes
Complete the bake_time_remaining() function that takes the actual minutes the lasagna has been in the
oven as an argument and returns how many minutes the lasagna still needs to bake based on the
EXPECTED_BAKE_TIME constant.
text
>>> bake_time_remaining(30)
10
3. Calculate preparation time in minutes
Define the preparation_time_in_minutes() function that takes the number_of_layers you want to add to
the lasagna as an argument and returns how many minutes you would spend making them. Assume each
layer takes 2 minutes to prepare.
text
...
...
>>> preparation_time_in_minutes(2)
• elapsed_bake_time (the number of minutes the lasagna has spent baking in the oven already).
This function should return the total minutes you have been in the kitchen cooking — your preparation
time layering + the time the lasagna has spent baking in the oven.
text
...
26
Go back through the recipe, adding "notes" in the form of function docstrings.
text
def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
"""Calculate the elapsed cooking time.
This function takes two integers representing the number of lasagna layers and the
time already spent baking and calculates the total elapsed minutes spent cooking the
lasagna.
"""
Python Fundamentals
• Name Assignment (variables and constants). Example: my_var = 5 assigns 5 to my_var; constants
like EXPECTED_BAKE_TIME = 40.
• Functions (the def keyword and the return keyword). Example: def add(a, b): return a + b defines
a function that adds two numbers.
1. What is a constant in Python? Answer: A variable that shouldn't change, named in UPPER_CASE,
e.g., PI = 3.14.
2. How do you define a function? Answer: Using def keyword, e.g., def func(): pass.
3. What does return do? Answer: It returns a value from the function.
4. How to write comments? Answer: Using # for single-line, or triple quotes for multi-line.
5. What is a docstring? Answer: A string for documenting functions, accessible via doc.
6. Why use variables? Answer: To store and reuse data values.
7. What is the difference between = and ==? Answer: = assigns values; == compares equality.
8. How to calculate time in minutes? Answer: Use arithmetic operators like - for subtraction.
10. Why add docstrings to functions? Answer: For better code readability and documentation.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Guido's Gorgeous Lasagna" exercise was implemented successfully. All four functions correctly
calculate the expected bake time, remaining time, preparation time, and total elapsed time. The program
passes all tests. Basic function writing and arithmetic operations were verified.
Exercise No: 3
Date: __________
Two Fer
Imagine a bakery that has a holiday offer where you can buy two cookies for the price of one ("two-fer
one!"). You take the offer and (very generously) decide to give the extra cookie to someone else in the
queue.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Two Fer" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand that you need to create a "two-fer" phrase with an
optional name.
6. In the online editor, look at the left side where the stub function is provided (takes a name
parameter with default).
7. Understand the given stub code: you need to return a formatted string.
8. Write your solution step-by-step: use a default value for the name and format the required
phrase.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., wrong string
format or default handling).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
3. Create the string in the format "One for [name], one for me."
Your task is to determine what you will say as you give away the extra cookie.
If you know the person's name (e.g. if they're named Do-yun), then you will say:
text
If you don't know the person's name, you will say you instead.
text
One for you, one for me.
Name Dialogue
Python Fundamentals
• String formatting with f-strings or format(). Example: f"One for {name}, one for me."
• Function parameters with defaults. Example: def two_fer(name="you"): return f"One for {name},
one for me."
• Conditional statements if-else. Example: if name else "you".
• String concatenation. Example: "One for " + name + ", one for me."
1. What is string interpolation? Answer: Inserting variables into strings, e.g., using f-strings.
3. What is an if statement? Answer: Controls flow based on condition, e.g., if condition: code.
4. Why use functions? Answer: For reusable code blocks.
7. What is return type in Python? Answer: Functions can return any type, including strings.
8. Difference between + and f-string for strings? Answer: + concatenates; f-string formats
dynamically.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Two Fer" exercise was implemented successfully. The function returns the correct "two-fer"
phrase with proper default value handling. All test cases pass. String formatting and default parameter
concepts were verified.
Exercise No: 4
Date: __________
High Scores
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and
most addictive games of all time, and a classic of the arcade era. Your task is to write methods that return
the highest score from the list, the last added score and the three highest scores.
In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find
yourself using them again and again in problems both simple and complex.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "High Scores" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand the class methods needed for managing scores.
6. In the online editor, look at the left side where the class stub with methods is provided.
7. Understand the given stub code: you need to implement methods using list operations.
8. Write your solution step-by-step: store scores and implement latest, personal best, and personal
top three.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., sorting or list
issues).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and
most addictive games of all time, and a classic of the arcade era. Your task is to write methods that return
the highest score from the list, the last added score and the three highest scores.
In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find
yourself using them again and again in problems both simple and complex.
Python Fundamentals
• List operations like max(), sorted(). Example: max(scores) gets highest score.
7. Difference between sort() and sorted()? Answer: sort() modifies in-place; sorted() returns new
list.
8. How to get top n elements? Answer: sorted(list, reverse=True)[:n].
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "High Scores" exercise was implemented successfully. The class correctly returns the latest score,
personal best, and personal top three scores. All tests pass. List operations, sorting, and class methods
were verified.
Exercise No: 5
Date: __________
The assignment has four activities, each with a set of text or words to work with.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Little Sister's Vocab" exercise and click
on it to open the exercise page.
4. Read the instructions carefully. Understand the string manipulation tasks for prefixes, suffixes,
and word groups.
6. In the online editor, look at the left side where multiple stub functions are provided.
7. Understand the given stub code: each function performs a different string operation.
8. Write your solution step-by-step: implement each function using string concatenation, slicing,
and join().
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., wrong prefix or
spacing).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
2. For make_word_groups: add the prefix to each word and join with "::".
3. For remove_suffix_ness: remove "ness" and adjust the word if needed (e.g., remove extra 'i').
4. For adjective_to_verb: change adjective to verb form by adding "en" after removing suffix.
One of the most common prefixes in English is un, meaning "not". In this activity, your sister needs to
make negative, or "not" words by adding un to them.
Implement the add_prefix_un(<word>) function that takes word as a parameter and returns a new un
prefixed word:
text
>>> add_prefix_un("happy")
'unhappy'
>>> add_prefix_un("manageable")
'unmanageable'
In this exercise, the class is creating groups of vocabulary words using these prefixes, so they can be
studied together. Each prefix comes in a list with common words it's used with. The students need to
apply the prefix and produce a string that shows the prefix applied to all of the words.
Implement the make_word_groups(<vocab_words>) function that takes a vocab_words as a parameter
in the following form: [<prefix>, <word_1>, <word_2> .... <word_n>], and returns a string with the
prefix applied to each word that looks like: '<prefix> :: <prefix><word_1> :: <prefix><word_2> ::
<prefix><word_n>'.
Creating a for or while loop to process the input is not needed here. Think carefully about which string
methods (and delimiters) you could use instead.
text
ness is a common suffix that means 'state of being' . In this activity, your sister needs to find the original
root word by removing the ness suffix. But of course there are pesky spelling rules: If the root word
originally ended in a consonant followed by a 'y', then the 'y' was changed to 'i'. Removing 'ness' needs
to restore the 'y' in those root words. e.g. happiness --> happi --> happy .
Implement the remove_suffix_ness(<word>) function that takes in a word, and returns the root word
without the ness suffix.
text
>>> remove_suffix_ness("heaviness")
'heavy'
>>> remove_suffix_ness("sadness")
'sad'
4. Extract and transform a word
Suffixes are often used to change the part of speech a word is assigned to. A common practice in English
is "verbing" or "verbifying" -- where an adjective becomes a verb by adding an en suffix.
In this task, your sister is going to practice "verbing" words by extracting an adjective from a sentence
and turning it into a verb. Fortunately, all the words that need to be transformed here are "regular" - they
don't need spelling changes to add the suffix.
Implement the adjective_to_verb(<sentence>, <index>) function that takes two parameters. A sentence
using the vocabulary word, and the index of the word, once that sentence is split apart. The function
should return the extracted adjective as a verb.
text
'brighten'
'darken'
Python Fundamentals
• String concatenation and prefixes/suffixes. Example: "un" + word.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Little Sister's Vocab" exercise was implemented successfully. All string transformation functions
for prefixes, suffixes, word groups, and adjective-to-verb conversions work correctly. All tests pass.
String manipulation techniques were verified.
Exercise No: 6
Date: __________
List Ops
In functional languages list operations like length, map, and reduce are very common. Implement a series
of basic list operations, without using existing functions.
The precise number and names of the operations to be implemented will be track dependent to avoid
conflicts with existing names, but the general operations you will implement include:
• append (given two lists, add all items in the second list to the end of the first list);
• concatenate (given a series of lists, combine all items in all lists into one flattened list);
• filter (given a predicate and a list, return the list of all items for which predicate(item) is True);
• length (given a list, return the total number of items within it);
• map (given a function and a list, return the list of the results of applying function(item) on all
items);
• foldl (given a function, a list, and initial accumulator, fold (reduce) each item into the accumulator
from the left);
• foldr (given a function, a list, and an initial accumulator, fold (reduce) each item into the
accumulator from the right);
• reverse (given a list, return a list with all the original items, but in reversed order).
Note, the ordering in which arguments are passed to the fold functions ( foldl, foldr) is significant.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "List Ops" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand you must implement list operations without using
many built-in functions.
5. Click the button to Open in Online Editor.
6. In the online editor, look at the left side where multiple stub functions are provided.
7. Understand the given stub code: each function performs a basic list operation.
8. Write your solution step-by-step: use loops to implement append, concat, filter, map, fold,
length, and reverse.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., index or loop
errors).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. For each operation, process the input list(s) using simple for loops.
3. For filter and map: apply the given function to each element.
4. For fold: accumulate a result by applying the function across the list.
In functional languages list operations like length, map, and reduce are very common. Implement a series
of basic list operations, without using existing functions.
The precise number and names of the operations to be implemented will be track dependent to avoid
conflicts with existing names, but the general operations you will implement include:
• append (given two lists, add all items in the second list to the end of the first list);
• concatenate (given a series of lists, combine all items in all lists into one flattened list);
• filter (given a predicate and a list, return the list of all items for which predicate(item) is True);
• length (given a list, return the total number of items within it);
• map (given a function and a list, return the list of the results of applying function(item) on all
items);
• foldl (given a function, a list, and initial accumulator, fold (reduce) each item into the accumulator
from the left);
• foldr (given a function, a list, and an initial accumulator, fold (reduce) each item into the
accumulator from the right);
• reverse (given a list, return a list with all the original items, but in reversed order).
Note, the ordering in which arguments are passed to the fold functions ( foldl, foldr) is significant.
Python Fundamentals
6. Difference between foldl and foldr? Answer: foldl from left; foldr from right.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "List Ops" exercise was implemented successfully. All list operations including append, concat,
filter, map, fold, length, and reverse work correctly using loops. All tests pass. Manual list processing
and loop logic were verified.
Exercise No: 7
Date: __________
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Little Sister's Essay" exercise and click
on it to open the exercise page.
4. Read the instructions carefully. Understand the text cleaning and formatting rules for the essay.
6. In the online editor, look at the left side where the stub functions for cleaning text are provided.
7. Understand the given stub code: you need to fix capitalization, spacing, and punctuation.
8. Write your solution step-by-step: implement functions to capitalize sentences, fix spaces, and
handle punctuation.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., wrong spacing or
capitalization).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
Any good paper needs a properly formatted title. Implement the function capitalize_title(<title>) which
takes a title str as a parameter and capitalizes the first letter of each word. This function should return a
str in title case.
text
"My Hobbies"
You want to make sure that the punctuation in the paper is perfect. Implement the function
check_sentence_ending() that takes sentence as a parameter. This function should return a bool.
text
3. Clean up spacing
To make the paper look professional, unnecessary spacing needs to be removed. Implement the function
clean_up_spacing() that takes sentence as a parameter. The function should remove extra whitespace at
both the beginning and the end of the sentence, returning a new, updated sentence str.
text
To make the paper even better, you can replace some of the adjectives with their synonyms. Write the
function replace_word_choice() that takes sentence, old_word, and new_word as parameters. This
function should replace all instances of the old_word with the new_word, and return a new str with the
updated sentence.
text
Python Fundamentals
1. What does [Link]() do? Answer: Capitalizes first letter of each word.
9. Difference between strip() and rstrip()? Answer: strip() both sides; rstrip() right.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Little Sister's Essay" exercise was implemented successfully. The essay text is properly cleaned
with correct capitalization, spacing, and punctuation. All tests pass. Advanced string processing and
text formatting were verified.
Exercise No: 8
Date: __________
Isogram
An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter, however
spaces and hyphens are allowed to appear multiple times.
Examples of isograms:
• lumberjacks
• background
• downstream
• six-year-old
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Isogram" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand that an isogram is a word with no repeating letters
(ignoring case and hyphens/spaces).
5. Click the button to Open in Online Editor.
6. In the online editor, look at the left side where the stub function is provided.
7. Understand the given stub code: you need to check for unique letters.
8. Write your solution step-by-step: convert to lowercase and use a set to track seen letters.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., case sensitivity or
non-letter handling).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter, however
spaces and hyphens are allowed to appear multiple times.
Examples of isograms:
• lumberjacks
• background
• downstream
• six-year-old
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Isogram" exercise was implemented successfully. The function correctly identifies isograms by
detecting repeating letters while ignoring case and non-letters. All tests pass. Set usage and string
normalization were verified.
Exercise No: 9
Date: __________
Anagram
You realize this quirk allows you to generate anagrams, which are words formed by rearranging the letters
of another word. Pleased with your finding, you spend the rest of the day generating hundreds of
anagrams.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Anagram" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand how to find anagrams from a list of candidates.
6. In the online editor, look at the left side where the stub function is provided.
7. Understand the given stub code: compare the subject word with candidates.
8. Write your solution step-by-step: normalize words by sorting letters and compare.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., case or exact
match issues).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. Normalize the subject word: convert to lowercase and sort its letters.
2. For each candidate word: normalize it the same way (lowercase + sorted letters).
3. If the normalized versions match and the candidate is not the same as the subject (case-
insensitive), it is an anagram.
An anagram is a rearrangement of letters to form a new word: for example "owns" is an anagram of
"snow". A word is not its own anagram: for example, "stop" is not an anagram of "stop".
The target word and candidate words are made up of one or more ASCII alphabetic characters ( A- Z and
a- z). Lowercase and uppercase characters are equivalent: for example, "PoTS" is an anagram of "sTOp",
but "StoP" is not an anagram of "sTOp". The words you need to find should be taken from the candidate
words, using the same letter case.
Given the target "stone" and the candidate words "stone", "tones", "banana", "tons", "notes", and "Seton",
the anagram words you need to find are "tones", "notes", and "Seton".
Python Fundamentals
6. How to handle different lengths? Answer: Sorted will differ if lengths differ.
9. Difference from isogram? Answer: Anagram compares two words; isogram no repeats in one.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Anagram" exercise was implemented successfully. The function correctly finds all anagrams from
the candidate list by comparing letter patterns. All tests pass. String normalization and pattern matching
were verified.
Exercise No: 10
Date: __________
Hamming
When cells divide, their DNA replicates too. Sometimes during this process mistakes happen and single
pieces of DNA get encoded with the incorrect information. If we compare two strands of DNA and count
the differences between them, we can see how many mistakes occurred. This is known as the "Hamming
distance".
The Hamming distance is useful in many areas of science, not just biology, so it's a nice phrase to be
familiar with :)
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Hamming" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand how to calculate the Hamming distance between
two DNA strands.
6. In the online editor, look at the left side where the stub function is provided.
7. Understand the given stub code: compare two strings of equal length.
8. Write your solution step-by-step: check lengths and count differing positions.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., length mismatch
or count error).
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. Check if both strands have the same length; raise an error if not.
We read DNA using the letters C, A, G and T. Two strands might look like this:
text
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^^^ ^^ ^^
Implementation notes
The Hamming distance is only defined for sequences of equal length, so an attempt to calculate it between
sequences of different lengths should not work.
Exception messages
Sometimes it is necessary to raise an exception. When you do this, you should always include a
meaningful error message to indicate what the source of the error is. This makes your code more readable
and helps significantly with debugging. For situations where you know that the error source will be a
certain type, you can choose to raise one of the built in error types, but should still include a meaningful
message.
This particular exercise requires that you use the raise statement to "throw" a ValueError when the strands
being checked are not the same length. The tests will only pass if you both raise the exception and include
a message with it.
To raise a ValueError with a message, write the message as an argument to the exception type:
text
# When the sequences being passed are not the same length.
3. What is sum with generator? Answer: sum(condition for ... ) counts Trues.
4. When to raise ValueError? Answer: For invalid input like unequal lengths.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Hamming" exercise was implemented successfully. The Hamming distance is calculated correctly
between DNA strands with proper length validation. All tests pass. String iteration and error handling
were verified.
Exercise No: 11
Date: __________
Raindrops
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Raindrops" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand the rules for converting numbers to raindrop sounds.
6. In the online editor, look at the left side where the stub function is provided.
8. Write your solution step-by-step: build the result string based on factors.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., missing sound or
wrong number output).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
If a given number:
Examples
Note
A common way to test if one number is evenly divisible by another is to compare the remainder or
modulus to zero. Most languages provide operators or functions for one (or both) of these.
Python Fundamentals
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Raindrops" exercise was implemented successfully. Numbers are correctly converted to raindrop
sounds (Pling, Plang, Plong) according to the divisibility rules. All tests pass. Conditional logic and
string building were verified.
Exercise No: 12
Date: __________
Grade School
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Grade School" exercise and click on it
to open the exercise page.
4. Read the instructions carefully. Understand how to manage a school roster by grade.
6. In the online editor, look at the left side where the class stub with add and roster methods is
provided.
7. Understand the given stub code: use a dictionary to store students by grade.
8. Write your solution step-by-step: add students and maintain sorted rosters.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., sorting or grade
lookup).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. Use a dictionary where keys are grade numbers and values are lists of student names.
2. When adding a student, append the name to the correct grade list and keep the list sorted.
3. For the full roster: collect all students sorted first by grade, then by name.
4. For a specific grade: return the sorted list of students in that grade.
o "OK."
• Get a sorted list of all students in all grades. Grades should be sorted as 1, 2, 3, etc., and students
within a grade should be sorted alphabetically by name.
o "Let me think. We have Anna, Barb, and Charlie in grade 1, Alex, Peter, and Zoe in grade
2, and Jim in grade 5. So the answer is: Anna, Barb, Charlie, Alex, Peter, Zoe, and Jim."
Note that all our students only have one name (it's a small town, what do you want?), and each student
cannot be added more than once to a grade or the roster. If a test attempts to add the same student more
than once, your implementation should indicate that this is incorrect.
The tests for this exercise expect your school roster will be implemented via a School class in Python. If
you are unfamiliar with classes in Python, classes from the Python docs is a good place to start.
Python Fundamentals
• Classes and methods. Example: class School: def add_student(self, name, grade): ...
• Dictionaries for rosters. Example: [Link] = {} with grade as key, list of names as value.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Grade School" exercise was implemented successfully. The school roster is correctly managed
with students grouped by grade and properly sorted. All tests pass. Dictionary and list management
were verified.
Exercise No: 13
Date: __________
You have four rules to implement, all related to the game states.
Do not worry about how the arguments are derived, just focus on combining the arguments to return the
intended result.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Ghost Gobble Arcade Game" exercise
and click on it to open the exercise page.
4. Read the instructions carefully. Understand the Pac-Man style boolean rules for eating ghosts,
scoring, losing, and winning.
6. In the online editor, look at the left side where multiple boolean stub functions are provided.
7. Understand the given stub code: each function returns True or False based on conditions.
8. Write your solution step-by-step: implement each rule using logical operators (and, or, not).
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., wrong
combination of conditions).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. eat_ghost: return True only if power pellet is active AND touching a ghost.
3. lose: return True if touching a ghost AND power pellet is NOT active.
4. win: return True if all dots are eaten AND the lose condition is False.
Define the eat_ghost() function that takes two parameters ( if Pac-Man has a power pellet active and if
Pac-Man is touching a ghost) and returns a Boolean value if Pac-Man is able to eat a ghost. The function
should return True only if Pac-Man has a power pellet active and is touching a ghost.
text
...
False
Define the score() function that takes two parameters ( if Pac-Man is touching a power pellet and if Pac-
Man is touching a dot) and returns a Boolean value if Pac-Man scored. The function should return True
if Pac-Man is touching a power pellet or a dot.
text
>>> score(True, True)
...
True
Define the lose() function that takes two parameters ( if Pac-Man has a power pellet active and if Pac-
Man is touching a ghost) and returns a Boolean value if Pac-Man loses. The function should return True
if Pac-Man is touching a ghost and does not have a power pellet active.
text
>>> lose(False, True)
...
True
text
...
False
Python Fundamentals
• Conditional logic.
Paste/Write your Code
5. What is Pac-Man rule for eat? Answer: Power and touching ghost.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Ghost Gobble Arcade Game" exercise was implemented successfully. All Pac-Man style game
rules for eating ghosts, scoring, losing, and winning return correct boolean values. All tests pass.
Logical operators were verified.
Exercise No: 14
Date: __________
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Making the Grade" exercise and click
on it to open the exercise page.
4. Read the instructions carefully. Understand the functions for rounding scores, counting passed
students, and assigning letter grades.
8. Write your solution step-by-step: use loops or list comprehensions for rounding, filtering, and
averaging.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., rounding or
threshold issues).
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. round_scores: round each score to the nearest integer using a loop or list comprehension.
2. count_failed_students: count how many scores are below the passing threshold.
• Round student scores according to rules (e.g., round up to the next multiple of 5 if the difference
is less than 3, but only for scores 38 or higher).
• Analyze class performance, such as counting passing students or calculating average scores.
Example:
• Score 90 → Grade A.
• Modulo and arithmetic: Use % and // for rounding. Example: score + (5 - score % 5) if score % 5
> 2 else score.
• Conditional statements: Use if-elif-else for grading logic.
• List comprehensions: Example: [s for s in scores if s >= 40] for passing students.
1. What is the rounding rule for grades? Answer: If score ≥ 38 and next multiple of 5 is within 3,
round up.
3. What is a list comprehension? Answer: Concise way to create lists, e.g., [x for x in list if
condition].
4. How to assign letter grades? Answer: Use if-elif with score ranges.
6. How to count passing students? Answer: len([s for s in scores if s >= 40]).
7. What is integer division? Answer: // gives quotient, e.g., 10 // 3 = 3.
8. How to handle empty score list? Answer: Return 0 or empty list as needed.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Making the Grade" exercise was implemented successfully. Student scores are correctly rounded,
filtered, graded with letter grades, and ranked. All tests pass. List processing and grade calculations
were verified.
Exercise No: 15
Date: __________
Eliud's Eggs
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Eliud's Eggs" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand the task is to count the number of 1s in the binary
representation of a number.
5. Click the button to Open in Online Editor.
6. In the online editor, look at the left side where the stub function is provided.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., wrong count).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
1. Initialize a counter to 0.
Given a number, convert it to binary and count the number of 1s, as each 1 represents an egg. For example:
• Number 5 (binary 101) → 2 eggs.
Python Fundamentals
1. What is bin()? Answer: Converts int to binary string, e.g., bin(5) = '0b101'.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Eliud's Eggs" exercise was implemented successfully. The number of set bits (eggs) in the binary
representation is counted correctly. All tests pass. Bitwise operations and number manipulation were
verified.
Exercise No: 16
Date: __________
Armstrong Numbers
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Armstrong Numbers" exercise and click
on it to open the exercise page.
4. Read the instructions carefully. Understand that an Armstrong number equals the sum of its
digits raised to the power of the number of digits.
5. Click the button to Open in Online Editor.
6. In the online editor, look at the left side where the stub function is provided.
8. Write your solution step-by-step: calculate the sum of powered digits and compare.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., power calculation
error).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
An Armstrong number is a number that is the sum of its own digits each raised to the power of the number
of digits. For example:
Python Fundamentals
1. What is an Armstrong number? Answer: Sum of digits raised to number of digits equals number.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Armstrong Numbers" exercise was implemented successfully. Numbers are correctly identified as
Armstrong numbers by summing powered digits. All tests pass. Mathematical power calculations and
digit extraction were verified.
Exercise No: 17
Date: __________
Grains
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Grains" exercise and click on it to open
the exercise page.
4. Read the instructions carefully. Understand the doubling grains on a chessboard.
6. In the online editor, look at the left side where the stub functions for square and total are
provided.
8. Write your solution step-by-step: use exponentiation for each square and sum for total.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., overflow or
wrong value).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
Calculate:
Python Fundamentals
• Power operator: 2 ** (n-1) for square.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Grains" exercise was implemented successfully. The correct number of grains per square and the
total grains on the 64-square chessboard are calculated accurately. All tests pass. Large integer handling
with exponentiation was verified.
Exercise No: 18
Date: __________
Currency Exchange
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Currency Exchange" exercise and click
on it to open the exercise page.
4. Read the instructions carefully. Understand exchanging money with exchange rates and fees.
6. In the online editor, look at the left side where the stub functions are provided.
7. Understand the given stub code: perform calculations with rates and budgets.
8. Write your solution step-by-step: implement exchange, change, and maximum amount
functions.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., floating point or
comparison issues).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
4. Use basic arithmetic and return the calculated float or boolean values.
Given an amount and a list of coin denominations, find the minimum number of coins needed. Return -
1 if impossible. Example:
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Currency Exchange" exercise was implemented successfully. All currency exchange calculations
including exchanged value, change, and maximum affordable amount work correctly. All tests pass.
Floating-point arithmetic and financial calculations were verified.
Exercise No: 19
Date: __________
Gigasecond
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Gigasecond" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand adding one billion seconds to a given date/time.
6. In the online editor, look at the left side where the stub function and datetime usage is shown.
8. Write your solution step-by-step: create a timedelta of 10**9 seconds and add it to the input.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., import or
timedelta error).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
Given a datetime, return the datetime after adding 1,000,000,000 seconds. Example:
• Timedelta: timedelta(seconds=10**9).
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Gigasecond" exercise was implemented successfully. One billion seconds are correctly added to
the input date and time using the datetime module. All tests pass. Date and time handling was verified.
Exercise No: 20
Date: __________
ETL
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "ETL" exercise and click on it to open
the exercise page.
4. Read the instructions carefully. Understand transforming the old scoring system to a new
format.
5. Click the button to Open in Online Editor.
6. In the online editor, look at the left side where the stub transform function is provided.
7. Understand the given stub code: convert dictionary of scores to letters into letter-to-score.
8. Write your solution step-by-step: use dictionary comprehension or loops to invert the mapping.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., case or key
issues).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
2. For each score and its list of letters in the old system:
Transform {1: ['A', 'B'], 2: ['C']} to {'a': 1, 'b': 1, 'c': 2}. Convert letters to lowercase.
Python Fundamentals
• Dictionary comprehension: {[Link](): score for score, letters in [Link]() for letter in
letters}.
10. Example input? Answer: {1: ['A', 'B']} → {'a': 1, 'b': 1}.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "ETL" exercise was implemented successfully. The old scoring system is correctly transformed
into the new letter-to-score format. All tests pass. Dictionary transformation and data restructuring were
verified.
Exercise No: 21
Date: __________
Prime Factors
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Prime Factors" exercise and click on it
to open the exercise page.
4. Read the instructions carefully. Understand finding all prime factors of a number.
6. In the online editor, look at the left side where the stub function is provided.
10. Check the test results. If any test fails, read the error messages carefully (e.g., loop condition or
missing factors).
11. Debug and fix the issues in the code editor.
12. Re-run the tests until all tests pass (you will see a green success message).
13. Once all tests pass, click Submit to send your solution.
14. After submission, you can click Publish to share your solution with the community for
feedback or learning.
Algorithm:
Python Fundamentals
• Loops: Divide by smallest prime.
• Modulo: n % d == 0.
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Prime Factors" exercise was implemented successfully. All prime factors of the given number are
found and returned in ascending order. All tests pass. Number factorization algorithm was verified.
Exercise No: 22
Date: ________
Word Search
In word search puzzles, you get a square of letters and have to find specific words hidden within them.
Words can be concealed in various directions: left-to-right, right-to-left, vertically, or diagonally. This
challenge involves implementing a program that locates these words and returns the positions of their
first and last letters, much like uncovering hidden gems in a letter grid.
Imagine you are an explorer with a cryptic map made of letters, where secret words representing ancient
artifacts are buried in straight lines across the terrain. Your quest is to scan the map systematically in all
possible paths to pinpoint the start and end coordinates of each discovered word.
Procedure:
1. Open your web browser and go to the Exercism website ([Link]). Click on "Sign Up" or
"Log In" using your GitHub, Google, or email account.
2. After logging in, click on "Tracks" and select the Python track.
3. On the Python track dashboard, scroll or search for the "Word Search" exercise and click on it to
open the exercise page.
4. Read the instructions carefully. Understand finding words in a letter grid in any of 8 directions.
6. In the online editor, look at the left side where the stub function or class is provided.
7. Understand the given stub code: search the 2D grid for each word.
8. Write your solution step-by-step: check every starting position and all directions.
9. Click the Run Tests button on the right side to execute the test suite.
10. Check the test results. If any test fails, read the error messages carefully (e.g., direction or
boundary issues).
Algorithm:
▪ If the word is fully matched within bounds, record the start and end
coordinates.
3. Return a dictionary with each found word mapped to its location details.
Your task is to determine the positions of words hidden in a square letter grid.
You are given a puzzle as a list of strings (each string a row of the grid) and a list of words to find. For
each word found, return the 0-based row and column indices of its first and last letters as a tuple (r1, c1,
r2, c2).
The function signature is: def find_word_positions(puzzle: list[str], words: list[str]) -> list[tuple[int, int,
int, int]]
If you don't find the word, simply omit it from the output list.
Word Positions
java (0, 0, 3, 3)
clojure (9, 0, 9, 6)
ruby (5, 7, 8, 4)
lisp (5, 2, 2, 5)
Python Fundamentals
• Lists and nested structures (e.g., list of strings as 2D grid). Example: puzzle[ row ][ col ]
• Loops (for nested loops over rows and columns). Example: for r in range(len(puzzle)): for c in
range(len(puzzle[0])):
RUBRICS
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10
Result
The "Word Search" exercise was implemented successfully. All words are correctly located in the letter
grid across all eight directions with proper coordinates. All tests pass. 2D grid traversal and multi-
directional search were verified.