Lab 8 (Year 2 Sem 1)

Lab 8 is the 9th lab in semester 1 of year 2, and the 9th lab in the total of year 2. It is a lab for string processing, and is considered to be easy.

Description
No description was provided for this lab.

Unlocked after completion

 * Intern of the Year (Score at least 60% for Lab 8: String Processing)
 * Checked! (Score at least 60% for Lab 8: String Processing)
 * Perfect in Practice (Score at least 60% for Lab 8: String Processing)
 * String Manipulator (Score at least 80% for Lab 8: String Processing)
 * Challenge 5: String Processing (Complete Lab 8: String Processing)

Question
This question is very simple. Just store the following string in a variable named

aaaaa...aaaabbbbb...bbbb

where there are 1000 a's and 1000 b's.

Solution
either use a for loop or string multiplication

Question
Complete the function named  which takes in a string, and replaces all the upper case characters for lower case ones and vice versa.

For example, "This is a Test" will become "tHIS IS A tEST"

Question
Your annoying cousin has just made a website in which all the text has vertical bars to separate each character because he thinks that it makes text easier to read. You strongly disapprove of this practice. Help write a function  that takes in some text and removes the vertical bars.

For example remove_bars('|H|e|l|l|o| |W|o|r|l|d|') returns 'Hello World'

Question
Complete the function named  which takes in three arguments, a string, a substring and an integer and returns a string with the substring inserted into the string at the position defined by the integer.

For example  returns

You may assume that i is between 0 and len(string)+1 inclusive.

Solution
there is no str.insert in python, but lists have list.insert

concatenate the strings with + and slice with str[start:end]

Question
Write a function  which will take in a word and returns True if the word has a vowel, False otherwise. Vowels are 'a', 'e', 'i', 'o' and 'u'. You may assume the input word are in small letters.

Solution
iterate over strings with for loops

check if substring occurs in string

Question
Complete the function  which takes in a single word and converts it to pig latin.

(Simplified) Rules for converting to pig latin:

1) Move the first alphabet to the back of the word

2) Add the substring 'ay' to the back

Solution
you know how to slice and concatenate strings (see question 4)

Question
Complete the function  which takes in a single word and converts it to pig latin.

Rules for converting to pig latin:
 * For words that begin with a vowel (a, e, i, o, u), add "way"
 * Otherwise, move all letters before the first vowel to the end and add "ay"

Use the function  coded in the previous question to help code this function. You may assume there is at least one vowel in the input.

You need to copy and past your code for   here.

Solution
this is a combination of everything you have learned

remember to paste in !