SlideShare a Scribd company logo
Techno India University,W.B.
Department of Computer Applications
Subject:-Tools and Techniques of Programming
using Python
ASSIGNMENT-4
Topic: Strings in Python
December 19, 2021
Develop Python scripts to solve following problems:
1. A program is required to be written that prompts the user to enter
a string. The program should then print the following:
(a) The total number of characters in the string
(b) The string repeated 5 times
(c) The first character of the string
(d) The first four characters of the string
(e) The last two characters of the string
(f) The string in the reversed form
(g) The ninth character of the string if the string is long enough
and a message otherwise
(h) The string with its first and last characters removed
(i) The string in all the letters in capital form
(j) The string with every ‘i’ replaced with an ‘I’
(k) The string with every letter replaced by a space
2. A program is required to be written that prompts the user to enter
a string and returns the number of words in the string.
1
3. It has been observed that programmers often forget to type the
closing parentheses when formulas are entered. Develop a program
that asks the user to enter a formula and prints out whether the
entered formula contains the same number of opening and closing
parentheses.
4. Develop a program that asks the user to enter a string and prints
out whether the string contains any vowel or not.
5. Develop a program that asks the user to enter a string to create a
new string called new_str from the given string such that the third
character is changed to an asterisk and two signs of exclamation are
attached to the end of the string. Finally, the program prints out
the new_str.
6. Develop a program that prompts the user to enter a string str for
its conversion to lowercase by removing all the periods and commas
from it, and shows the resulting string.
7. A program is required to be developed for the following outputs out
of a given string: for counting the number of sentences in the given
string and for counting the number of lines in the given string.
8. In a certain university named TIU, the email addresses of the stu-
dents end with @student.tiu.edu, while the email addresses of the
professors end with @prof.tiu.edu. It is required to develop a pro-
gram that first asks the user the number of email addresses he/she
will enter, and then it will allow the user enter those addresses. Af-
ter completion of the entry, the program is required to print out a
message showing the number of entered email address belonging to
each category.
9. Develop a program that prompts the user to input a string, then
prints out each letter of the string tripled in a separate line. For
instance, if the input is DAD , the output would be DDD AAA
DDD
10. A program is required to be developed for deciphering a given string
of code numbers into its equivalent alphabetic letters by using the
following rules:
2
(a) A number is to be treated as an ASCII decimal value of a char-
acter
(b) 5 is to be added to the value before converting it into a letter
(c) If addition of 5 takes the new value to some value that exceeds
the range of letters then 10 is to be subtracted from the sum for
translating it into a letter.
(d) Spaces in it will remain spaces.
(e) Three digits are to be taken at a time for the translation.
(f) Finally , the translated code is to be shown.
11. Develop a program that prompts the user to enter a word that
contains a chosen letter given as input. If the letter is not contained
in the word, then the program is required to generate a message
regarding that; otherwise, it will print the part of the word up to
that given letter in a separate line and the rest in the next line. For
example, if the input word is ‘Coward’ and the given letter is ‘w’,
then the output would look like the following one: Coward
12. Develop a program that prompts the user to enter a word; it then
capitalizes every alternate letter of that word and shows the result-
ing word. So if the input word is ‘elephant’, then the out will be:
eLePhAnT.
13. It is required to develop a program that prompts the user to enter
two strings of equal length. The program then checks to see if the
strings are really of the same length. If they are not, the program
should then print an appropriate message and exit. If they are of
the same length, the program should then concatenate the strings
by taking alternate characters from the two strings and prints the
resulting string. For instance, if the user enters ‘Book’ and ‘Star’
the output should be BSotoakr.
14. Let us have a long string of a few sentences as input in a program
with some missing words represented with hyphens. The program
will then asks for a few types of words for insertion in places of the
hyphens. The program then replaces the hyphens with the given
words and prints the reconstructed text. The resulting string may
3
be a funny one. Nevertheless, we need to develop the code. For
instance, Let the input text be: Tiger is a – animal. It likes to eat
-. It lives in -.
Now, the questions may be like the following ones:
Enter an adjective: happy
Enter the name of a food item: noodles
Enter the name of a place: city
Now, we have the following reconstructed string: Tiger is a happy
animal. It likes to eat noodles. It lives in city.
15. Develop a program for the following activities:
(a) Without using the in operator, the program asks the user for
a string and a letter and prints out whether or not the letter
appears in the string.
(b) Without using the count method, the program asks the user
for a string and a letter and counts how many times the letter
occurs in the string.
(c) Without using the index method, the program that asks the
user for a string and a letter and prints out the index of the
first occurrence of the letter in the string. If the letter is not in
the string, the program should say so.
16. Write a program that asks the user for a large integer and inserts
commas into it according to the standard convention for commas in
large numbers. For instance, if the user enters 12345678, the output
should be 12,345,678.
17. A program is required to be developed for generating all possible
permutations of words with all the letters in the word. For example,
if the given word is ‘bit’, the different possible words will be: bit,
tib, tbi, bti, tib, ibt.
18. One simple way of encrypting a message is by rearranging its char-
acters. One way to rearrange the characters is to pick out the char-
acters at odd indices, put them first in the encrypted string, and
follow them by the characters at the even positions. For instance,
the message ‘Save our Soul’ would be encrypted as: Sv u oliaeorSu
4
(a) Develop a program that prompts the user for a string and uses
this method to encrypt the string to show the encrypted message.
(b) Develop a program to decrypt a string that was encrypted with
this method. 19. A more general version of the above technique
is the rail fence cipher, where instead of breaking things into evens
and odds, they are broken up by threes, fours or something larger.
(a) Develop a program the prompts the user for a string and uses
the rail fence cipher in the threes case to encrypt the string.
(b) Write a decryption program for the threes case.
(c) Write a program that asks the user for a string, and an integer
determining whether to break things up by threes, fours, or
whatever. Encrypt the string using the rail-fence cipher.
(d) Write a decryption program for the general case.
19. In calculus, the derivative of x5 is 5x4. The derivative of x3 is 3x2.
This pattern continues. Develop a program that prompts the user
for input like x3
or x2
5 and shows the derivative.
20. In algebraic expressions, the symbol for multiplication is often omit-
ted, as in 5x+7y or5(x+3). Computers cannot operate on those
expressions. It is required to develop a program that prompts the
user for an algebraic expression and then inserts the multiplication
symbols where appropriate.
21. Develop a Python script named showTable that takes a list of lists
of strings for
(a) Printing it in a well-organized table with each column right-
justified. Assume that all the inner lists will contain the same
number of strings. For example, the value could look like this:
tableData = [[’Jasmine’, ’Rose, ’Tulip’, ’Chrysanthe-
mum’], [’Julia’, ’Jahanara’, ’Manasi’, ’Tapasi’],
[’is akin to’, ’resembles’, ’reminds me the name of’, ’is
another name for’]]
(b) Make sentences by combining each word from the second list
with the corresponding phrase in the second list followed by
the corresponding word from the first list.For example, the first
sentence would be: Julia is akin to Jasmin.
5
Hint for part 1: The code may first find out the longest string in each of the inner lists so that the whole column can be made
wide enough to fit all the strings. The maximum width of each column can be stored as a list of integers. The printTable()
function can begin with colWidths = [0] * len(tableData), which will create a list containing the same number of 0 values
as the number of inner lists in tableData. That way, colWidths[0] can store the width of the longest string in tableData[0],
colWidths[1] can store the width of the longest string in tableData[1], and so on. Then , the largest value in the colWidths
list can be determined to find out what integer width to pass to the rjust() string method.
6

More Related Content

What's hot

Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python C. ASWINI
 
Huffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalHuffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalEkansh Agarwal
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by pythonJaya Kumari
 
C and CPP Interview Questions
C and CPP Interview QuestionsC and CPP Interview Questions
C and CPP Interview QuestionsSagar Joshi
 
introduction to python
 introduction to python introduction to python
introduction to pythonJincy Nelson
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by FaixanٖFaiXy :)
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1Srinimf-Slides
 
Python Interview questions 2020
Python Interview questions 2020Python Interview questions 2020
Python Interview questions 2020VigneshVijay21
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisRamakant Soni
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding09lavee
 
Huffman's Alforithm
Huffman's AlforithmHuffman's Alforithm
Huffman's AlforithmRoohaali
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 
Stringing Things Along
Stringing Things AlongStringing Things Along
Stringing Things AlongKevlin Henney
 
Multimedia lossless compression algorithms
Multimedia lossless compression algorithmsMultimedia lossless compression algorithms
Multimedia lossless compression algorithmsMazin Alwaaly
 

What's hot (18)

Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Huffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalHuffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh Agarwal
 
Rubykin
Rubykin Rubykin
Rubykin
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
 
C++
C++C++
C++
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 
C and CPP Interview Questions
C and CPP Interview QuestionsC and CPP Interview Questions
C and CPP Interview Questions
 
introduction to python
 introduction to python introduction to python
introduction to python
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
 
Lossless
LosslessLossless
Lossless
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1
 
Python Interview questions 2020
Python Interview questions 2020Python Interview questions 2020
Python Interview questions 2020
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding
 
Huffman's Alforithm
Huffman's AlforithmHuffman's Alforithm
Huffman's Alforithm
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Stringing Things Along
Stringing Things AlongStringing Things Along
Stringing Things Along
 
Multimedia lossless compression algorithms
Multimedia lossless compression algorithmsMultimedia lossless compression algorithms
Multimedia lossless compression algorithms
 

Similar to Python assignment 4

INSTRUCTIONS For this assignment you will be generating all code on y.pdf
 INSTRUCTIONS For this assignment you will be generating all code on y.pdf INSTRUCTIONS For this assignment you will be generating all code on y.pdf
INSTRUCTIONS For this assignment you will be generating all code on y.pdfadayarboot
 
(4) cpp automatic arrays_pointers_c-strings_exercises
(4) cpp automatic arrays_pointers_c-strings_exercises(4) cpp automatic arrays_pointers_c-strings_exercises
(4) cpp automatic arrays_pointers_c-strings_exercisesNico Ludwig
 
علم البيانات - Data Sience
علم البيانات - Data Sience علم البيانات - Data Sience
علم البيانات - Data Sience App Ttrainers .com
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxABDULAHAD507571
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxadihartanto7
 
C language
C languageC language
C languageSMS2007
 
Lab6: I/O and Arrays
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arraysenidcruz
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfKosmikTech1
 
Assignment 1 for 2nd sem
Assignment 1 for 2nd semAssignment 1 for 2nd sem
Assignment 1 for 2nd semhome
 
C basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaC basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaManoj Kumar kothagulla
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointersenidcruz
 
Cosc 1436 java programming/tutorialoutlet
Cosc 1436 java programming/tutorialoutletCosc 1436 java programming/tutorialoutlet
Cosc 1436 java programming/tutorialoutletWoodardz
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...manikamr074
 
Hey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addiHey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addisorayan5ywschuit
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers Appili Vamsi Krishna
 

Similar to Python assignment 4 (20)

INSTRUCTIONS For this assignment you will be generating all code on y.pdf
 INSTRUCTIONS For this assignment you will be generating all code on y.pdf INSTRUCTIONS For this assignment you will be generating all code on y.pdf
INSTRUCTIONS For this assignment you will be generating all code on y.pdf
 
(4) cpp automatic arrays_pointers_c-strings_exercises
(4) cpp automatic arrays_pointers_c-strings_exercises(4) cpp automatic arrays_pointers_c-strings_exercises
(4) cpp automatic arrays_pointers_c-strings_exercises
 
qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdfqb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
 
علم البيانات - Data Sience
علم البيانات - Data Sience علم البيانات - Data Sience
علم البيانات - Data Sience
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 
C language
C languageC language
C language
 
Lab6: I/O and Arrays
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arrays
 
Java programlist (1)
Java programlist (1)Java programlist (1)
Java programlist (1)
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Programming Practice Questions_C
Programming Practice Questions_CProgramming Practice Questions_C
Programming Practice Questions_C
 
Assignment 1 for 2nd sem
Assignment 1 for 2nd semAssignment 1 for 2nd sem
Assignment 1 for 2nd sem
 
C basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaC basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kella
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
 
Cosc 1436 java programming/tutorialoutlet
Cosc 1436 java programming/tutorialoutletCosc 1436 java programming/tutorialoutlet
Cosc 1436 java programming/tutorialoutlet
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
 
Hey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addiHey i have attached the required file for my assignment.and addi
Hey i have attached the required file for my assignment.and addi
 
10 Jo P Oct 07
10 Jo P Oct 0710 Jo P Oct 07
10 Jo P Oct 07
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfThiyagu K
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxJisc
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...EugeneSaldivar
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...Jisc
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)rosedainty
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chipsGeoBlogs
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...SachinKumar945617
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasGeoBlogs
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

Python assignment 4

  • 1. Techno India University,W.B. Department of Computer Applications Subject:-Tools and Techniques of Programming using Python ASSIGNMENT-4 Topic: Strings in Python December 19, 2021 Develop Python scripts to solve following problems: 1. A program is required to be written that prompts the user to enter a string. The program should then print the following: (a) The total number of characters in the string (b) The string repeated 5 times (c) The first character of the string (d) The first four characters of the string (e) The last two characters of the string (f) The string in the reversed form (g) The ninth character of the string if the string is long enough and a message otherwise (h) The string with its first and last characters removed (i) The string in all the letters in capital form (j) The string with every ‘i’ replaced with an ‘I’ (k) The string with every letter replaced by a space 2. A program is required to be written that prompts the user to enter a string and returns the number of words in the string. 1
  • 2. 3. It has been observed that programmers often forget to type the closing parentheses when formulas are entered. Develop a program that asks the user to enter a formula and prints out whether the entered formula contains the same number of opening and closing parentheses. 4. Develop a program that asks the user to enter a string and prints out whether the string contains any vowel or not. 5. Develop a program that asks the user to enter a string to create a new string called new_str from the given string such that the third character is changed to an asterisk and two signs of exclamation are attached to the end of the string. Finally, the program prints out the new_str. 6. Develop a program that prompts the user to enter a string str for its conversion to lowercase by removing all the periods and commas from it, and shows the resulting string. 7. A program is required to be developed for the following outputs out of a given string: for counting the number of sentences in the given string and for counting the number of lines in the given string. 8. In a certain university named TIU, the email addresses of the stu- dents end with @student.tiu.edu, while the email addresses of the professors end with @prof.tiu.edu. It is required to develop a pro- gram that first asks the user the number of email addresses he/she will enter, and then it will allow the user enter those addresses. Af- ter completion of the entry, the program is required to print out a message showing the number of entered email address belonging to each category. 9. Develop a program that prompts the user to input a string, then prints out each letter of the string tripled in a separate line. For instance, if the input is DAD , the output would be DDD AAA DDD 10. A program is required to be developed for deciphering a given string of code numbers into its equivalent alphabetic letters by using the following rules: 2
  • 3. (a) A number is to be treated as an ASCII decimal value of a char- acter (b) 5 is to be added to the value before converting it into a letter (c) If addition of 5 takes the new value to some value that exceeds the range of letters then 10 is to be subtracted from the sum for translating it into a letter. (d) Spaces in it will remain spaces. (e) Three digits are to be taken at a time for the translation. (f) Finally , the translated code is to be shown. 11. Develop a program that prompts the user to enter a word that contains a chosen letter given as input. If the letter is not contained in the word, then the program is required to generate a message regarding that; otherwise, it will print the part of the word up to that given letter in a separate line and the rest in the next line. For example, if the input word is ‘Coward’ and the given letter is ‘w’, then the output would look like the following one: Coward 12. Develop a program that prompts the user to enter a word; it then capitalizes every alternate letter of that word and shows the result- ing word. So if the input word is ‘elephant’, then the out will be: eLePhAnT. 13. It is required to develop a program that prompts the user to enter two strings of equal length. The program then checks to see if the strings are really of the same length. If they are not, the program should then print an appropriate message and exit. If they are of the same length, the program should then concatenate the strings by taking alternate characters from the two strings and prints the resulting string. For instance, if the user enters ‘Book’ and ‘Star’ the output should be BSotoakr. 14. Let us have a long string of a few sentences as input in a program with some missing words represented with hyphens. The program will then asks for a few types of words for insertion in places of the hyphens. The program then replaces the hyphens with the given words and prints the reconstructed text. The resulting string may 3
  • 4. be a funny one. Nevertheless, we need to develop the code. For instance, Let the input text be: Tiger is a – animal. It likes to eat -. It lives in -. Now, the questions may be like the following ones: Enter an adjective: happy Enter the name of a food item: noodles Enter the name of a place: city Now, we have the following reconstructed string: Tiger is a happy animal. It likes to eat noodles. It lives in city. 15. Develop a program for the following activities: (a) Without using the in operator, the program asks the user for a string and a letter and prints out whether or not the letter appears in the string. (b) Without using the count method, the program asks the user for a string and a letter and counts how many times the letter occurs in the string. (c) Without using the index method, the program that asks the user for a string and a letter and prints out the index of the first occurrence of the letter in the string. If the letter is not in the string, the program should say so. 16. Write a program that asks the user for a large integer and inserts commas into it according to the standard convention for commas in large numbers. For instance, if the user enters 12345678, the output should be 12,345,678. 17. A program is required to be developed for generating all possible permutations of words with all the letters in the word. For example, if the given word is ‘bit’, the different possible words will be: bit, tib, tbi, bti, tib, ibt. 18. One simple way of encrypting a message is by rearranging its char- acters. One way to rearrange the characters is to pick out the char- acters at odd indices, put them first in the encrypted string, and follow them by the characters at the even positions. For instance, the message ‘Save our Soul’ would be encrypted as: Sv u oliaeorSu 4
  • 5. (a) Develop a program that prompts the user for a string and uses this method to encrypt the string to show the encrypted message. (b) Develop a program to decrypt a string that was encrypted with this method. 19. A more general version of the above technique is the rail fence cipher, where instead of breaking things into evens and odds, they are broken up by threes, fours or something larger. (a) Develop a program the prompts the user for a string and uses the rail fence cipher in the threes case to encrypt the string. (b) Write a decryption program for the threes case. (c) Write a program that asks the user for a string, and an integer determining whether to break things up by threes, fours, or whatever. Encrypt the string using the rail-fence cipher. (d) Write a decryption program for the general case. 19. In calculus, the derivative of x5 is 5x4. The derivative of x3 is 3x2. This pattern continues. Develop a program that prompts the user for input like x3 or x2 5 and shows the derivative. 20. In algebraic expressions, the symbol for multiplication is often omit- ted, as in 5x+7y or5(x+3). Computers cannot operate on those expressions. It is required to develop a program that prompts the user for an algebraic expression and then inserts the multiplication symbols where appropriate. 21. Develop a Python script named showTable that takes a list of lists of strings for (a) Printing it in a well-organized table with each column right- justified. Assume that all the inner lists will contain the same number of strings. For example, the value could look like this: tableData = [[’Jasmine’, ’Rose, ’Tulip’, ’Chrysanthe- mum’], [’Julia’, ’Jahanara’, ’Manasi’, ’Tapasi’], [’is akin to’, ’resembles’, ’reminds me the name of’, ’is another name for’]] (b) Make sentences by combining each word from the second list with the corresponding phrase in the second list followed by the corresponding word from the first list.For example, the first sentence would be: Julia is akin to Jasmin. 5
  • 6. Hint for part 1: The code may first find out the longest string in each of the inner lists so that the whole column can be made wide enough to fit all the strings. The maximum width of each column can be stored as a list of integers. The printTable() function can begin with colWidths = [0] * len(tableData), which will create a list containing the same number of 0 values as the number of inner lists in tableData. That way, colWidths[0] can store the width of the longest string in tableData[0], colWidths[1] can store the width of the longest string in tableData[1], and so on. Then , the largest value in the colWidths list can be determined to find out what integer width to pass to the rjust() string method. 6