0% found this document useful (0 votes)
6 views102 pages

New Python Lab Manual - Non CS Streams

The document is a record work template for the Python Programming Lab course at SNS College of Technology for the academic year 2025-2026. It includes exercises for students to complete, such as 'Hello World', 'Guido's Gorgeous Lasagna', and 'Two Fer', each with specific aims, procedures, algorithms, and viva questions. The document also contains sections for student information, exercise results, and rubrics for grading.

Uploaded by

ramguru0398
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views102 pages

New Python Lab Manual - Non CS Streams

The document is a record work template for the Python Programming Lab course at SNS College of Technology for the academic year 2025-2026. It includes exercises for students to complete, such as 'Hello World', 'Guido's Gorgeous Lasagna', and 'Two Fer', each with specific aims, procedures, algorithms, and viva questions. The document also contains sections for student information, exercise results, and rubrics for grading.

Uploaded by

ramguru0398
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SNS COLLEGE OF TECHNOLOGY

COIMBATORE

23ITP102-PYTHON PROGRAMMING LAB


(Common to all Department)

ACADEMIC YEAR 2025-2026


EVEN SEMESTER

RECORD WORK

Name of the Student :

Register Number :

Year & Department :

Semester :
SNS COLLEGE OF TECHNOLOGY
Coimbatore
(An Autonomous Institution)

Name : …………………………………………………………

Year & Dept : …………………………………………………………

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

Signature of Lab-in-charge Head of the Department

Submitted for the Practical Examination held on …………….

Internal Examiner External Examiner


INDEX
PAGE SIGNATURE
[Link]. DATE NAME OF THE EXERCISE MARKS
NO. OF STAFF
PAGE SIGNATURE
[Link]. DATE NAME OF THE EXERCISE MARKS
NO. OF STAFF

AVERAGE MARK (10) :

FACULTY SIGNATURE
PASTE YOUR EXERCISM OVERVIEW SCREENSHOT
Exercise No: 1

Date: __________

Hello World

Aim of The Exercism Challenge


“Hello, World!” will get you writing some Python and familiarize yourself with the Exercism workflow.
Completing it unlocks the rest of the Python Track.

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

5. Click the button to Open in Online Editor.


6. In the online editor, look at the left side where the stub code is provided (usually a function like
def hello() or similar with a pass statement).

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.

3. Simply return the required string from the function.


4. No calculations or conditions are needed — it is a basic introduction to the platform and Python
syntax.

Instruction of the Exercism Challenge

The classical introductory exercise. Just say "Hello, World!".


"Hello, World!" is the traditional first program for beginning programming in a new language or
environment.

The objectives are simple:

• Modify the provided code so that it produces the string "Hello, World!".

• Run the test suite and make sure that it succeeds.

• Submit your solution and check it at the website.

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

[Paste/write your successfully submitted code here]


Viva Questions
1. What is the purpose of the "Hello World" program? Answer: It is a simple program to verify that
the programming environment is set up correctly and to introduce basic syntax.
2. How do you print a string in Python? Answer: Use the print() function, e.g., print("Hello,
World!").
3. What is a function in Python? Answer: A function is defined using def and can return values, e.g.,
def my_func(): return "value".
4. What are comments used for? Answer: Comments explain code and are ignored by the interpreter,
starting with #.
5. What is a docstring? Answer: A multi-line string for documentation, placed inside functions or
classes using triple quotes.
6. Why is Python case-sensitive? Answer: It distinguishes between uppercase and lowercase letters
in variables and keywords.
7. What does return do in a function? Answer: It sends a value back from the function and ends its
execution.
8. How do you run Python code? Answer: Use the python command in the terminal, e.g., python
[Link].
9. What is the difference between print() and return? Answer: print() outputs to console; return sends
a value from a function.
10. Why use Exercism for learning? Answer: It provides practice exercises with automated tests and
mentor feedback.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3


2 Code Correctness & Functionality 3
Understanding of Python 3
3
Fundamentals
4 Viva Voce 1
5 Total 10

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: __________

Guido's Gorgeous Lasagna

Aim of The Exercism Challenge


You're going to write some code to help you cook a gorgeous lasagna from your favorite cookbook. This
first exercise introduces 4 major Python language features: Name Assignment (variables and constants),
Functions (the def keyword and the return keyword), Comments, and Docstrings.

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

5. Click the button to Open in Online Editor.

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

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. Define the expected bake time as a constant (40 minutes).

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.

5. Return the correct value from each function.


Instruction of the Exercism Challenge

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.

1. Define expected bake time in minutes as a constant

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

>>> def preparation_time_in_minutes(number_of_layers):

...

...

>>> preparation_time_in_minutes(2)

4. Calculate total elapsed time (prepping + baking) in minutes

Define the elapsed_time_in_minutes() function that takes two parameters as arguments:

• number_of_layers (the number of layers added to the lasagna)

• 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

>>> def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):


...

...

>>> elapsed_time_in_minutes(3, 20)

26

5. Update the recipe with notes

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.

:param number_of_layers: int - the number of layers in the lasagna.

:param elapsed_bake_time: int - elapsed cooking time.


:return: int - total time elapsed (in minutes) preparing and cooking.

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.

• Comments. Example: # This is a comment for explanation.


• Docstrings. Example: """This describes the function.""" placed after def line.
Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

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.

9. What is indentation in Python? Answer: It defines code blocks, like in functions.

10. Why add docstrings to functions? Answer: For better code readability and documentation.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


In some English accents, when you say "two for" quickly, it sounds like "two fer". Two-for-one is a way
of saying that if you buy one, you also get one for free. So the phrase "two-fer" often implies a two-for-
one offer.

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.

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

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. Check if a name is provided to the function.

2. If no name is given, use "you" as the default.

3. Create the string in the format "One for [name], one for me."

4. Return the formatted string.


Instruction of the Exercism Challenge

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

One for Do-yun, one for me.

If you don't know the person's name, you will say you instead.

text
One for you, one for me.

Here are some examples:

Name Dialogue

Alice One for Alice, one for me.

Bohdan One for Bohdan, one for me.

One for you, one for me.

Zaphod One for Zaphod, one for me.

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

Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is string interpolation? Answer: Inserting variables into strings, e.g., using f-strings.

2. How to set default parameters in functions? Answer: def func(param="default"):

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.

5. What is a parameter? Answer: A value passed to a function.

6. How to handle missing arguments? Answer: Use default values.

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.

9. What is None? Answer: A special value representing nothing.

10. Why test functions? Answer: To ensure they work as expected.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Manage a game player's High Score list.

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.

5. Click the button to Open in Online Editor.

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

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. Store the list of scores in the class.

2. Latest score: return the last score in the list.

3. Personal best: find and return the highest score.


4. Personal top three: sort scores in descending order and return the first three.

5. Return the appropriate value or list from each method.

Instruction of the Exercism Challenge

Manage a game player's High Score list.

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.

• List indexing and slicing. Example: scores[-1] for last score.

• Sorting lists. Example: sorted(scores, reverse=True)[:3] for top three.

• List append. Example: [Link](new_score).


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. How to find max in list? Answer: Use max(list).

2. What is list slicing? Answer: list[start:end] to get sublist.

3. How to sort a list descending? Answer: sorted(list, reverse=True).


4. What is negative indexing? Answer: list[-1] is last element.

5. How to add to list? Answer: [Link](value).

6. What is len()? Answer: Returns length of list.

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

9. What if list is empty? Answer: max() raises ValueError.

10. Why use lists? Answer: For ordered collections of items.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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: __________

Little Sister's Vocab

Aim of The Exercism Challenge


You are helping your younger sister with her English vocabulary homework, which she is finding very
tedious. Her class is learning to create new words by adding prefixes and suffixes. Given a set of words,
the teacher is looking for correctly transformed words with correct spelling by adding the prefix to the
beginning or the suffix to the ending.

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.

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

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. For add_prefix_un: add "un" at the beginning of the word.

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.

5. Return the modified string from each function.

Instruction of the Exercism Challenge

1. Add a prefix to a word

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'

2. Add prefixes to word groups


There are four more common prefixes that your sister's class is studying: en ( meaning to 'put into' or
'cover with'), pre ( meaning 'before' or 'forward'), auto ( meaning 'self' or 'same'), and inter ( meaning
'between' or 'among').

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

>>> make_word_groups(['en', 'close', 'joy', 'lighten'])

'en :: enclose :: enjoy :: enlighten'

>>> make_word_groups(['pre', 'serve', 'dispose', 'position'])


'pre :: preserve :: predispose :: preposition'

>> make_word_groups(['auto', 'didactic', 'graph', 'mate'])

'auto :: autodidactic :: autograph :: automate'

>>> make_word_groups(['inter', 'twine', 'connected', 'dependent'])

'inter :: intertwine :: interconnected :: interdependent'

3. Remove a suffix from a word

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

>>> adjective_to_verb('I need to make that bright.', -1 )

'brighten'

>>> adjective_to_verb('It got dark as the sun set.', 2)

'darken'

Python Fundamentals
• String concatenation and prefixes/suffixes. Example: "un" + word.

• String join for groups. Example: "::".join(words).

• String slicing for removing suffixes. Example: word[:-4].

• String replace for spelling rules. Example: [Link]("i", "y").

• String split and indexing. Example: [Link]()[index].


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. How to add prefix to string? Answer: prefix + string.

2. What is [Link]()? Answer: Joins iterable with separator.

3. How to remove suffix? Answer: Use slicing if fixed length.


4. What is [Link]()? Answer: Replaces substrings.

5. How to split sentence? Answer: [Link]().

6. What is index in list? Answer: Position starting from 0.

7. Negative index? Answer: -1 is last element.

8. Why handle spelling rules? Answer: For correct word transformation.

9. What is a list? Answer: Ordered collection.

10. How to access list element? Answer: list[index].

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Implement basic list operations.

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

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. For each operation, process the input list(s) using simple for loops.

2. Build new lists by appending elements as needed.

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.

5. Return the resulting list or value for each function.

Instruction of the Exercism Challenge


Implement basic list operations.

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

• List concatenation. Example: list1 + list2.

• Flatten lists with loops. Example: for sub in lists: [Link](sub).

• Filter with list comprehension. Example: [x for x in list if pred(x)].


• Length with loop. Example: count = 0; for _ in list: count += 1.

• Map with loop. Example: [func(x) for x in list].

• Fold/reduce with loop. Example: for x in list: acc = func(acc, x).

• Reverse with slicing. Example: list[::-1].


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is append? Answer: Adds element to list end.

2. How to concatenate lists? Answer: list1 + list2.

3. What is filter? Answer: Selects items based on condition.


4. How to calculate length without len()? Answer: Use a counter in loop.

5. What is map? Answer: Applies function to each item.

6. Difference between foldl and foldr? Answer: foldl from left; foldr from right.

7. How to reverse list without reverse()? Answer: list[::-1].

8. What is an accumulator? Answer: Value updated in reduce/fold.

9. Why avoid built-ins? Answer: To understand implementation.

10. What is a predicate? Answer: Function returning bool.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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: __________

Little Sister's Essay

Aim of The Exercism Challenge


In this exercise you are helping your younger sister edit her paper for school. The teacher is looking for
correct punctuation, grammar, and excellent word choice.

You have four tasks to clean up and modify strings.


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

5. Click the button to Open in Online Editor.

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

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. Split the text into sentences using punctuation as delimiters.

2. Capitalize the first letter of each sentence.

3. Fix extra spaces and ensure single spaces between words.


4. Ensure proper punctuation at the end of sentences.

5. Rejoin the cleaned sentences and return the formatted essay.

Instruction of the Exercism Challenge

1. Capitalize the title of the paper

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

>>> capitalize_title("my hobbies")

"My Hobbies"

2. Check if each sentence ends with a period

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

>>> check_sentence_ending("I like to hike, bake, and read.")


True

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

>>> clean_up_spacing(" I like to go on hikes with my dog. ")

"I like to go on hikes with my dog."


4. Replace words with a synonym

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

>>> replace_word_choice("I bake good cakes.", "good", "amazing")

"I bake amazing cakes."

Python Fundamentals

• [Link]() for capitalizing words. Example: "title case".title().

• [Link]() for checking ending. Example: [Link](".").

• [Link]() for removing whitespace. Example: " text ".strip().


• [Link]() for replacing words. Example: [Link]("old", "new").
Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What does [Link]() do? Answer: Capitalizes first letter of each word.

2. How to check string end? Answer: [Link](char).

3. What is [Link]()? Answer: Removes leading/trailing whitespace.


4. How to replace in string? Answer: [Link](old, new).

5. Is string mutable? Answer: No, methods return new strings.

6. What is bool return? Answer: True or False.

7. Why clean spacing? Answer: For clean text.

8. What if multiple replacements? Answer: replace() handles all instances.

9. Difference between strip() and rstrip()? Answer: strip() both sides; rstrip() right.

10. How to handle case in replace? Answer: replace() is case-sensitive.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Determine if a word or phrase is an 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

The word isograms, however, is not an isogram, because the s repeats.

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:

1. Convert the input string to lowercase.

2. Remove or ignore non-letter characters (like hyphens and spaces).


3. Use a set to store seen letters while iterating through the string.

4. If a letter is already in the set, return False; otherwise continue.


5. If no repeats found, return True.

Instruction of the Exercism Challenge

Determine if a word or phrase is an 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

The word isograms, however, is not an isogram, because the s repeats.


Python Fundamentals

• Sets for unique letters. Example: set([Link]()) to get unique.

• String lower(). Example: [Link]() for case-insensitivity.

• Loop through characters. Example: for char in word: ...


• Ignore spaces and hyphens. Example: if [Link](): ...
Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is an isogram? Answer: Word without repeating letters.

2. How to check unique characters? Answer: Compare len(set(str)) == len(str).

3. Why lower case? Answer: To ignore case differences.


4. What is set? Answer: Unordered unique collection.

5. How to ignore non-letters? Answer: Use isalpha().

6. What is [Link]()? Answer: True if all alphabetic.

7. Empty string isogram? Answer: Yes, no repeats.

8. Hyphens allowed? Answer: Yes, multiple ok.

9. What if numbers? Answer: Treat as non-letters.

10. Why use len comparison? Answer: If unique, lengths match.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


At a garage sale, you find a lovely vintage typewriter at a bargain price! Excitedly, you rush home, insert
a sheet of paper, and start typing away. However, your excitement wanes when you examine the output:
all words are garbled! For example, it prints "stop" instead of "post" and "least" instead of "stale."
Carefully, you try again, but now it prints "spot" and "slate." After some experimentation, you find there
is a random delay before each letter is printed, which messes up the order. You now understand why they
sold it for so little money!

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.

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

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

4. Collect all such anagrams in a list and return it.

Instruction of the Exercism Challenge


Given a target word and one or more candidate words, your task is to find the candidates that are anagrams
of the target.

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

• Sorted strings for comparison. Example: sorted([Link]()) == sorted([Link]()).

• Case-insensitivity. Example: [Link]().


• Exclude self. Example: if [Link]() != [Link]().

• List filtering. Example: [w for w in candidates if condition].


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is an anagram? Answer: Rearrangement of letters.

2. How to check anagram? Answer: Sort letters and compare.

3. Why lower case? Answer: To make case-insensitive.


4. Exclude same word? Answer: Check if not equal ignoring case.

5. What is sorted()? Answer: Returns sorted list.

6. How to handle different lengths? Answer: Sorted will differ if lengths differ.

7. What if non-letters? Answer: Assume alphabetic as per instructions.

8. Why list comprehension? Answer: Concise filtering.

9. Difference from isogram? Answer: Anagram compares two words; isogram no repeats in one.

10. Efficiency of sort? Answer: O(n log n) for n letters.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Your body is made up of cells that contain DNA. Those cells regularly wear out and need replacing,
which they achieve by dividing into daughter cells. In fact, the average human body experiences about
10 quadrillion cell divisions in a lifetime!

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.

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

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. Check if both strands have the same length; raise an error if not.

2. Initialize a counter to zero.

3. Loop through each position in the strands and compare characters.


4. Increment the counter whenever characters differ.

5. Return the final count as the Hamming distance.


Instruction of the Exercism Challenge

Calculate the Hamming distance between two DNA strands.

We read DNA using the letters C, A, G and T. Two strands might look like this:

text

GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT

^^^ ^^ ^^

They have 7 differences, and therefore the Hamming distance is 7.

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.

raise ValueError("Strands must be of equal length.")


Python Fundamentals

• Zip for pairing strands. Example: zip(strand1, strand2).

• Count differences. Example: sum(a != b for a, b in zip(...)).

• Length check. Example: if len(strand1) != len(strand2): raise ValueError.

• Loops or comprehensions for counting.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is Hamming distance? Answer: Number of differing positions in sequences.

2. How to iterate two strings? Answer: Use zip(str1, str2).

3. What is sum with generator? Answer: sum(condition for ... ) counts Trues.
4. When to raise ValueError? Answer: For invalid input like unequal lengths.

5. What if empty strands? Answer: Distance 0 if both empty.

6. Are strands case-sensitive? Answer: Yes, as per DNA letters.

7. What is zip? Answer: Pairs iterables.

8. Why check lengths first? Answer: To avoid partial comparison.

9. What if non-DNA letters? Answer: Assume valid as per instructions.

10. Efficiency? Answer: O(n) for n length.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Raindrops is a slightly more complex version of the FizzBuzz challenge, a classic interview question.

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.

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: check divisibility by 3, 5, and 7.

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:

1. Start with an empty result string.

2. If the number is divisible by 3, append "Pling".


3. If divisible by 5, append "Plang".
4. If divisible by 7, append "Plong".

5. If the result string is still empty, convert the number to a string.

6. Return the final result string.

Instruction of the Exercism Challenge


Your task is to convert a number into its corresponding raindrop sounds.

If a given number:

• is divisible by 3, add "Pling" to the result.

• is divisible by 5, add "Plang" to the result.

• is divisible by 7, add "Plong" to the result.

• is not divisible by 3, 5, or 7, the result should be the number as a string.

Examples

• 28 is divisible by 7, but not 3 or 5, so the result would be "Plong".


• 30 is divisible by 3 and 5, but not 7, so the result would be "PlingPlang".

• 34 is not divisible by 3, 5, or 7, so the result would be "34".

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

• Modulo operator %. Example: if n % 3 == 0: ...

• String concatenation based on conditions.


• If-elif-else for checks.

• Return string or str(n).


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is % operator? Answer: Remainder of division.

2. How to check divisibility? Answer: n % d == 0.

3. What if multiple conditions? Answer: Concatenate strings.


4. What if no condition? Answer: Return str(n).

5. Is order important? Answer: No, since separate checks.

6. What is FizzBuzz similar? Answer: Yes, but with sounds.

7. Handle large n? Answer: Yes, int handles.

8. Negative n? Answer: Assume positive as per natural numbers.

9. Zero? Answer: "0" since not divisible.

10. Why string return? Answer: For output format.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Given students' names along with the grade they are in, create a roster for the 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.

5. Click the button to Open in Online Editor.

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

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

Instruction of the Exercism Challenge

In the end, you should be able to:

• Add a student's name to the roster for a grade:


o "Add Jim to grade 2."

o "OK."

• Get a list of all students enrolled in a grade:

o "Which students are in grade 2?"

o "We've only got Jim right now."

• 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 "Who is enrolled in school right now?"

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.

• Sorted lists. Example: sorted(names).

• Prevent duplicates. Example: if name not in list.


• Get all students sorted by grade.
Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is a class? Answer: Blueprint for objects.

2. How to define method? Answer: def method(self): ...

3. What is self? Answer: Instance reference.


4. How to use dict for roster? Answer: {grade: [names]}.

5. How to sort students? Answer: sorted(list).

6. Prevent add same student? Answer: Check if in list.

7. Get students by grade? Answer: return [Link](grade, []).

8. All grades sorted? Answer: sorted([Link]()).

9. What if grade not exist? Answer: Create new list.

10. Why alphabet sort? Answer: For ordered output.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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: __________

Ghost Gobble Arcade Game

Aim of The Exercism Challenge


In this exercise, you need to implement some rules from Pac-Man, the classic 1980s-era arcade-game.

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.

5. Click the button to Open in Online Editor.

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

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. eat_ghost: return True only if power pellet is active AND touching a ghost.

2. score: return True if touching a power pellet OR touching a dot.

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.

5. Return the boolean result for each function.

Instruction of the Exercism Challenge

1. Define if Pac-Man eats a ghost

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

>>> eat_ghost(False, True)

...

False

2. Define if Pac-Man scores

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

3. Define if Pac-Man loses

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

4. Define if Pac-Man wins


Define the win() function that takes three parameters ( if Pac-Man has eaten all of the dots, if Pac-Man
has a power pellet active, and if Pac-Man is touching a ghost) and returns a Boolean value if Pac-Man
wins. The function should return True if Pac-Man has eaten all of the dots and has not lost based on the
parameters defined in part 3.

text

>>> win(False, True, False)

...

False
Python Fundamentals

• Boolean operators and, or, not. Example: power and touching.

• Function returning bool.

• Conditional logic.
Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is and operator? Answer: True if both true.

2. What is or? Answer: True if at least one true.

3. What is not? Answer: Inverts bool.


4. How to return bool? Answer: return condition.

5. What is Pac-Man rule for eat? Answer: Power and touching ghost.

6. For score? Answer: Pellet or dot.

7. For lose? Answer: Touching ghost and not power.

8. For win? Answer: All dots and not lose.

9. Why bool type? Answer: For true/false decisions.

10. What if all false? Answer: Depends on function.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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: __________

Making the Grade

Aim of The Exercism Challenge


The aim is to process student grades, performing tasks such as rounding scores according to specific
rules, calculating letter grades, and analyzing class performance to help manage academic records
efficiently.

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.

5. Click the button to Open in Online Editor.


6. In the online editor, look at the left side where the stub functions are provided.

7. Understand the given stub code: process lists of student scores.

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

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

3. above_threshold: return students whose scores are at or above a given value.


4. letter_grades: calculate grade boundaries and assign letters (A, B, C, D, F) based on thresholds.

5. student_ranking: pair students with their ranks and scores.

Instruction of the Exercism Challenge

This exercise involves implementing functions to:

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

• Convert numerical scores to letter grades (e.g., A, B, C).

• Analyze class performance, such as counting passing students or calculating average scores.
Example:

• Round 84 to 85 (next multiple of 5, difference < 3).

• Score 90 → Grade A.

• Count students with scores ≥ 40.


Python Fundamentals

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

• Functions: Define functions to handle each task.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is the rounding rule for grades? Answer: If score ≥ 38 and next multiple of 5 is within 3,
round up.

2. How to calculate next multiple of 5? Answer: score + (5 - score % 5).

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.

5. Why check score ≥ 38? Answer: To avoid rounding failing grades.

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.

9. Why use functions? Answer: For modularity and reuse.

10. What is average score? Answer: sum(scores) / len(scores) if non-empty.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Calculate the number of eggs a chicken produces based on a binary representation of a number, where
each 1 represents an egg laid on a specific day.

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.

7. Understand the given stub code: implement bit counting.

8. Write your solution step-by-step: use bitwise operations or binary conversion.

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

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. Initialize a counter to 0.

2. While the number is greater than 0:


o Add the least significant bit (number & 1) to the counter.
o Right-shift the number by 1 (number >>= 1).

3. Return the final count of 1 bits.

Instruction of the Exercism Challenge

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.

• Number 0 (binary 0) → 0 eggs.

Python Fundamentals

• Binary conversion: Use bin(n)[2:] to get binary string.

• Count 1s: Use [Link]('1') or sum of digits.

• Loops: Iterate over binary string, e.g., for d in bin(n)[2:].

• Type conversion: Convert int to string for processing.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is bin()? Answer: Converts int to binary string, e.g., bin(5) = '0b101'.

2. Why use [2:]? Answer: To remove '0b' prefix.

3. How to count 1s? Answer: bin(n)[2:].count('1').


4. What if number is 0? Answer: Returns 0 eggs.

5. Alternative to count()? Answer: Sum int(d) for d in bin(n)[2:].

6. Is binary case-sensitive? Answer: No, digits are 0 and 1.

7. Handle negative numbers? Answer: Assume non-negative.

8. What is type of bin() output? Answer: String.

9. Why count 1s? Answer: Each 1 is an egg.

10. Efficiency? Answer: O(log n) for binary digits.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Determine if a number is an Armstrong number, where the sum of its digits raised to the power of the
number of digits equals the number itself.

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.

7. Understand the given stub code: check if a number is an Armstrong number.

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:

1. Find the number of digits in the input number.

2. For each digit in the number:

o Raise the digit to the power of the number of digits.


o Add it to a running sum.

3. Compare the sum with the original number.

4. Return True if they are equal, otherwise False.

Instruction of the Exercism Challenge

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:

• 153 is an Armstrong number: 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.

• 10 is not: 1^2 + 0^2 = 1 ≠ 10.

Python Fundamentals

• String conversion: str(num) to get digits.


• Power operator: d ** len(str(num)).

• Sum comprehension: sum(int(d) ** len(str(num)) for d in str(num)).

• Length: len(str(num)) for digit count.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is an Armstrong number? Answer: Sum of digits raised to number of digits equals number.

2. How to get digits? Answer: Convert to string, iterate.

3. What is **? Answer: Power operator.


4. Single-digit numbers? Answer: All are Armstrong.

5. Why convert to string? Answer: Easy to iterate digits.

6. Handle zero? Answer: Not Armstrong, 0^1 = 0.

7. Efficiency concern? Answer: O(n) for n digits.

8. Negative numbers? Answer: Assume non-negative.

9. Use math module? Answer: Not needed, ** suffices.

10. Test example? Answer: 407: 4^3 + 0^3 + 7^3 = 407.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Calculate the number of grains on a chessboard where each square doubles the grains of the previous
square, starting with one grain on the first square.

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.

5. Click the button to Open in Online Editor.

6. In the online editor, look at the left side where the stub functions for square and total are
provided.

7. Understand the given stub code: calculate large powers of 2.

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:

1. For square(square_number): return 2 raised to the power of (square_number - 1).


2. For total: calculate the sum of grains on all 64 squares, which equals 2^64 - 1.
3. Return the integer result for each function.

Instruction of the Exercism Challenge

Calculate:

• Grains on a given square: 2^{n-1} for square n.


• Total grains on a 64-square chessboard: sum_{n=1}^{64} 2^{n-1}. Raise ValueError for invalid
squares (not 1 to 64).

Python Fundamentals
• Power operator: 2 ** (n-1) for square.

• Sum: sum(2 ** i for i in range(64)) for total.


• Exception: raise ValueError("Invalid square").

• Range: range(1, 65) for valid squares.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. Grains on square 1? Answer: 1 (2^0).

2. Formula for square n? Answer: 2^{n-1}.

3. Total grains formula? Answer: 2^{64} - 1.


4. Why ValueError? Answer: For invalid square numbers.

5. Range for squares? Answer: 1 to 64.

6. Handle large numbers? Answer: Python handles big ints.

7. Why double each square? Answer: Problem specification.

8. Zero square? Answer: Invalid, raise error.

9. Efficiency? Answer: Use geometric sum for total.

10. Alternative to loop? Answer: 2^{64} - 1 for total.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Calculate the fewest number of coins needed to make a given amount using provided denominations,
simulating a currency exchange problem.

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.

5. Click the button to Open in Online Editor.

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:

1. exchanged_value: calculate (budget / exchange_rate) minus the spread fee.


2. change: calculate the difference between budget and the exchanged amount.
3. max_amount: determine the maximum you can exchange or check if affordable.

4. Use basic arithmetic and return the calculated float or boolean values.

Instruction of the Exercism Challenge

Given an amount and a list of coin denominations, find the minimum number of coins needed. Return -
1 if impossible. Example:

• Amount 11, coins [1, 5, 10] → 3 (10 + 1).

• Amount 3, coins [2] → -1 (impossible).


Python Fundamentals

• Greedy algorithm: Try largest coins first.


• Loops: Iterate denominations in descending order.

• Modulo: amount % coin for remainder.

• Return -1: If amount cannot be made.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is greedy algorithm? Answer: Choose largest coin first.

2. When to return -1? Answer: If amount not possible.

3. How to sort coins? Answer: sorted(coins, reverse=True).


4. Why use modulo? Answer: To get remaining amount.

5. Handle zero amount? Answer: Return 0 coins.

6. What if no coins? Answer: Return -1 unless amount 0.

7. Efficiency? Answer: O(n) for n coins.

8. Alternative approach? Answer: Dynamic programming for non-greedy cases.

9. Why sort descending? Answer: To minimize coin count.

10. Example for 15, [1,5,10]? Answer: 2 (10 + 5).

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Calculate the date and time one gigasecond (1,000,000,000 seconds) after a given date, useful for time-
based calculations.

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.

5. Click the button to Open in Online Editor.

6. In the online editor, look at the left side where the stub function and datetime usage is shown.

7. Understand the given stub code: use Python's datetime module.

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

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. Import the necessary datetime and timedelta classes if needed.

2. Create a timedelta object representing 1,000,000,000 seconds.


3. Add this timedelta to the input datetime.
4. Return the new datetime object.

Instruction of the Exercism Challenge

Given a datetime, return the datetime after adding 1,000,000,000 seconds. Example:

• 2011-04-25 → 2043-01-01 01:46:40 (approx).


Python Fundamentals

• Datetime module: from datetime import datetime, timedelta.

• Timedelta: timedelta(seconds=10**9).

• Date addition: date + timedelta.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is a gigasecond? Answer: 1,000,000,000 seconds.

2. How to add time? Answer: Use timedelta.

3. What is datetime? Answer: Module for date/time.


4. Handle timezone? Answer: Assume naive datetime.

5. What is timedelta? Answer: Represents time duration.

6. Why 10**9? Answer: Gigasecond in seconds.

7. Output format? Answer: Datetime object.

8. Handle leap years? Answer: datetime handles automatically.

9. Efficiency? Answer: O(1) for addition.

10. Example for 2025-10-18? Answer: Approx 2057-06-26.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Transform a legacy data structure (dictionary mapping scores to letters) into a new format (dictionary
mapping letters to scores), simulating an extract-transform-load process.

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:

1. Create a new empty dictionary.

2. For each score and its list of letters in the old system:

o Convert each letter to lowercase.


o Assign the score to that letter as the key in the new dictionary.

3. Return the new transformed dictionary.

Instruction of the Exercism Challenge

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

• String methods: [Link]().

• Nested loops: Iterate scores, then letters.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is ETL? Answer: Extract, Transform, Load.

2. How to transform dict? Answer: Use comprehension or loops.

3. Why lowercase? Answer: Standardize output.


4. Handle empty dict? Answer: Return empty dict.

5. Nested loop alternative? Answer: Dictionary comprehension.

6. What is items()? Answer: Returns key-value pairs.

7. Overwrite keys? Answer: Last value wins.

8. Efficiency? Answer: O(n) for n letters.

9. Why new format? Answer: Easier lookup by letter.

10. Example input? Answer: {1: ['A', 'B']} → {'a': 1, 'b': 1}.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of The Exercism Challenge


Compute the prime factors of a given number, returning them in ascending order.

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.

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: implement factorization.

8. Write your solution step-by-step: use trial division starting from 2.


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

1. Initialize an empty list for factors.

2. Start with divisor = 2.


3. While the number is greater than 1:
o If the number is divisible by the divisor, add it to the list and divide the number by the
divisor.

o Else, increment the divisor (handle 2 separately then check odds).

4. Return the list of prime factors in ascending order.

Instruction of the Exercism Challenge

Given a number, return its prime factors. Example:

• 100 → [2, 2, 5, 5].


• 13 → [13].

Python Fundamentals
• Loops: Divide by smallest prime.

• Modulo: n % d == 0.

• List: Append factors.

• While: Continue until n == 1.


Paste/Write your Code

[Paste/Write your successfully submitted code here]


Viva Questions

1. What is prime factor? Answer: Prime number dividing n.

2. How to find factors? Answer: Divide by smallest prime.

3. Start with which prime? Answer: 2, then odd numbers.


4. Handle 1? Answer: Return empty list.

5. Efficiency? Answer: O(sqrt(n)) worst case.

6. Why ascending order? Answer: Natural factor order.

7. Composite number? Answer: Multiple prime factors.

8. Negative numbers? Answer: Assume positive.

9. Why while loop? Answer: Continue dividing.

10. Example for 28? Answer: [2, 2, 7].

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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

Aim of the Exercism Challenge

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.

5. Click the button to Open in Online Editor.

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

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. Convert the puzzle into a 2D list of characters.

2. For each word in the word list:

o For every possible starting row and column:

▪ For each of the 8 possible directions (delta row, delta column):


▪ Try to match the entire word by moving step-by-step in that direction.

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

Instruction of the Exercism Challenge

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

If a word is not found in the puzzle, do not include it in the results.

text for example

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.

Here are some examples:

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])):

• String indexing and slicing. Example: if puzzle[r][c] == word[0]

• Conditional statements (if-else). Example: if match: return position

• Functions with list parameters. Example: def find_word_positions(puzzle, words):


Paste/Write your Code

[Paste your successfully submitted code]


Viva Questions

1. What is a list in Python? Answer: An ordered, mutable collection of items.


2. How do you represent a 2D grid using lists? Answer: A list of strings or list of lists, accessed via
nested indexing.
3. What are for loops used for? Answer: Iterating over sequences like lists or ranges.
4. How do you check if a character matches in a string? Answer: Using indexing, e.g., string[index]
== char
5. What is a function parameter? Answer: A variable in the function definition that receives input
values.
6. How to handle boundaries in a grid search? Answer: Check if indices are within 0 to len-1 before
accessing.
7. What is the difference between == and in for strings? Answer: == checks equality; 'in' checks
substring.
8. What are tuples and when to use them? Answer: Immutable sequences; useful for fixed
coordinates like positions.
9. What is None? Answer: A special value representing nothing or absence.
10. Why test functions? Answer: To ensure they work as expected and handle edge cases.

RUBRICS

[Link] Parameters Maximum Marks Marks Earned

1 Code Completion & Submission 3

2 Code Correctness & Functionality 3

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.

You might also like