Python Programming Assignment: Sonnets and Doublets
VerifiedAdded on 2025/08/07
|9
|630
|210
AI Summary
Desklib provides solved assignments and past papers to help students succeed.

Table of Contents
Introduction.................................................................................................................................................2
Part 1:..........................................................................................................................................................3
Pseudo code:............................................................................................................................................3
Demonstration of code:...........................................................................................................................3
Python code:............................................................................................................................................4
Output:.....................................................................................................................................................5
Part 2:..........................................................................................................................................................6
Pseudo Code:...........................................................................................................................................6
Demonstration of code:...........................................................................................................................6
Python code:............................................................................................................................................7
Output:.....................................................................................................................................................8
Conclusion:.................................................................................................................................................9
Figure 1.......................................................................................................................................................4
Figure 2.......................................................................................................................................................5
Figure 3.......................................................................................................................................................5
Figure 4.......................................................................................................................................................7
Figure 5.......................................................................................................................................................8
Introduction.................................................................................................................................................2
Part 1:..........................................................................................................................................................3
Pseudo code:............................................................................................................................................3
Demonstration of code:...........................................................................................................................3
Python code:............................................................................................................................................4
Output:.....................................................................................................................................................5
Part 2:..........................................................................................................................................................6
Pseudo Code:...........................................................................................................................................6
Demonstration of code:...........................................................................................................................6
Python code:............................................................................................................................................7
Output:.....................................................................................................................................................8
Conclusion:.................................................................................................................................................9
Figure 1.......................................................................................................................................................4
Figure 2.......................................................................................................................................................5
Figure 3.......................................................................................................................................................5
Figure 4.......................................................................................................................................................7
Figure 5.......................................................................................................................................................8
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Introduction
This assignment is to check python skills for giving two problems related to Sonnets and
Doublets. Doublets have ladder of words that contain few words and each word has changed
with only one index value at every value and reach last End string or value. Sonnets are poems
that have lots of words containing letters, string, and sentences. So we have task to complete all
problem which defines in this assignment. Sonnets have three tasks that want to know how many
letters in given file and frequency of each word.
This assignment is to check python skills for giving two problems related to Sonnets and
Doublets. Doublets have ladder of words that contain few words and each word has changed
with only one index value at every value and reach last End string or value. Sonnets are poems
that have lots of words containing letters, string, and sentences. So we have task to complete all
problem which defines in this assignment. Sonnets have three tasks that want to know how many
letters in given file and frequency of each word.

Part 1:
This part is related to sonnets and here sonnets problem is solved using python code.
Pseudocode:
1. First, import all packages and read file and passed them in loop.
2. Run loop till file end string.
3. Make the counter variable and count the occurrence of words and set in List variable
4. Print whole list
5. Passed whole file variable in Counter class
6. Access whole Dictionary using a key-value form using loop till end of file
7 Sorted the file using in build functions.
8. End
Demonstration of code:
Read the file and passed in loop and run till file is finished. Using loop variable append all words
length to calculate one word two words and three-word letter and print it using loop variable in
form of key and value. For calculation of all words frequency, passed full file with applied split
function, in Counter class. So we need to import collections package and call it using collection
and Dot operator .it will return dictionary with words and its frequency. So print all data using
print function.
This part is related to sonnets and here sonnets problem is solved using python code.
Pseudocode:
1. First, import all packages and read file and passed them in loop.
2. Run loop till file end string.
3. Make the counter variable and count the occurrence of words and set in List variable
4. Print whole list
5. Passed whole file variable in Counter class
6. Access whole Dictionary using a key-value form using loop till end of file
7 Sorted the file using in build functions.
8. End
Demonstration of code:
Read the file and passed in loop and run till file is finished. Using loop variable append all words
length to calculate one word two words and three-word letter and print it using loop variable in
form of key and value. For calculation of all words frequency, passed full file with applied split
function, in Counter class. So we need to import collections package and call it using collection
and Dot operator .it will return dictionary with words and its frequency. So print all data using
print function.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Python code:
Figure 1
Figure 1
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Output:
Screenshot of the program is displayed below:
Figure 2
Figure 3
Screenshot of the program is displayed below:
Figure 2
Figure 3

Part 2:
Doublet's part is solved in this part. This is ladder of words that make word list, only changing
index value at each time.
Pseudo Code:
1. Read the file and passed it in function which returns all word text file.
2. We need words length, so make function which returns length of each word and store in list.
3. Create a function to Store all split word with possible split.
4. Create a method to Store all possible next words in Default dict.
5. Make Method which arranges given list of doublets.
6. Make a method that creates ladder of words and simply takes starting and ending string which
changes every index letter one by one till the end of string when target string is achieved.
7. Print function
8. End
Demonstration of code:
First, create a function total_word() which make words of list. Applied Split function arranges
possible word split. Make length function and item_required function which have functionality
to return length of all words and used strip() function in this code. Applied for loop and indexing
all words in given list. Append all words from default dictionary and return it.
find_total_function takes an argument with starting and end string which makes ladder of words
Appling for loop at the end of words and changes all ‘ i ‘ value one by one when last index if
founded .it will continue when target string is achieved.
Doublet's part is solved in this part. This is ladder of words that make word list, only changing
index value at each time.
Pseudo Code:
1. Read the file and passed it in function which returns all word text file.
2. We need words length, so make function which returns length of each word and store in list.
3. Create a function to Store all split word with possible split.
4. Create a method to Store all possible next words in Default dict.
5. Make Method which arranges given list of doublets.
6. Make a method that creates ladder of words and simply takes starting and ending string which
changes every index letter one by one till the end of string when target string is achieved.
7. Print function
8. End
Demonstration of code:
First, create a function total_word() which make words of list. Applied Split function arranges
possible word split. Make length function and item_required function which have functionality
to return length of all words and used strip() function in this code. Applied for loop and indexing
all words in given list. Append all words from default dictionary and return it.
find_total_function takes an argument with starting and end string which makes ladder of words
Appling for loop at the end of words and changes all ‘ i ‘ value one by one when last index if
founded .it will continue when target string is achieved.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Python code:
Figure 4
Figure 4
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Output:
Figure 5
Figure 5

Conclusion:
This program is successfully run. Sonnets and Doubles are two problems solved in this
assignment .we have successfully code the program of sonnets and Doublets problem in python.
The screenshot of the code and output is attached in this report file.
This program is successfully run. Sonnets and Doubles are two problems solved in this
assignment .we have successfully code the program of sonnets and Doublets problem in python.
The screenshot of the code and output is attached in this report file.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 9
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.