Skip to content

Latest commit

 

History

History
52 lines (32 loc) · 1.02 KB

exercise_3_solution.md

File metadata and controls

52 lines (32 loc) · 1.02 KB

Unit 1 Practice Solutions

Exercise 3

3.1

Capitalize a word

.capitalize() will convert the first letter in a string to uppercase.

.title() will convert the first letter of each word in a string to uppercase.

Solution

# Bicycle - using .capitalize()
print('bicycle'.capitalize()))

# Guitar - using .title()
print('guitar'.title())

3.2

Display a word in all capital letters and all lowercase letters

.upper() will convert all letters in a string to uppercase. .lower() will convert all letters in a string to lowercase.

Solution

# word: vIoLiN
print('vIoLiN'.upper() + ' ' + vIoLiN.lower())

3.3

Solution

Exchange all instances of a letter within a word with a different

The string method .replace(old, new) will replace the old character with the new character.

# Mizzizzippi
print('Mississippi'.replace('s','z'))