The Student Room Group

Python 2 string functions task

o Asks the user to enter their first and last name separately
o The program should ensure that anything entered for these has the first letter as a capital and the rest lower case
o Print out the first and last name together i.e Joe Bloggs
o Use ‘replace’ to swap some of the letters of your choice
o Print out the name again i.e. Joe Bloggs
o Print out the indexes of any vowels in the full name

Anyone know how I would do tasks 4 and 6.
Thanks in advance
For task 4, you need to get the variable you stored the name in, then call variable.replace('letterYouWantToReplace', 'lettersToReplaceWith')

For task 6, I would personally create a list of all the vowels (vowels = ['a', 'e', 'i', 'o', 'u']), then iterate (for loop) through all the letters of the string, and check to see if that letter is included in the vowel list (list.index(item)). Make sure you make the letters lowercase!

You can read more here:
https://www.geeksforgeeks.org/python-string-replace/
https://www.geeksforgeeks.org/python-list-index/
(edited 4 years ago)

Quick Reply

Latest

Trending

Trending