String 1

Exercise 1

Write a program to calculate the length of a string.

For example:

string = 'Practice makes perfect'

Length of this string is 20

Not allowed to use len() (不允许使用len()函数)

Exercise 2

Given a string consists of lower and upper case letters, write a program to convert lower case to upper case and upper case to lower case, return the result.

For example:

# Input
string = 'I hAVe UPPeR caSE AnD lowER CasE LETteRs'
# Output
result = 'i HavE uppEr CAse aNd LOWer cASe letTErS'

Hint: lower() and uppwer() are Python functions to convert upper to lower and vice versa.

For example:

string = 'a'
string.lower()
print(string) # result is A

Exercise 3

Given a string with random letters. Print vowels(元音字母) in a list.

For example:

# Input
string = "I'm looking for vowels"
# Write a function find_vowels()
def find_vowels(s):

# Output is ['i','o','e']
print(find_vowels(string))