CIS 41A Unit B, Exercise B
Write a single script that includes these two parts
At the top of your script, put the following multi-line comment with your information:
'''
Your name as registered, with optional nickname in parentheses
CIS 41A Fall 2021
Unit B, Exercise B
'''
1) String methods
- Ask the user for a name (test with George Washington).
- Print the name in all uppercase letters.
- Print the length of the name.
- Print the 4th character of the name (r).
-
Create a variable called name2.
Assign to name2 the name with all "o" characters replaced with "x"s.
- Print name2.
- Print the original name.
2) Counting and Finding
-
Assign the text
"Believe you can and you're halfway there."
to a variable called quote (this is a quote from Theodore Roosevelt).
- Count how many "a" characters there are, print the result.
- Print the index of all the "a" characters.
Hint: Except for the first find,
set the start location for the next find as the previous
location found index + 1.
The second argument in the find method is
the index where the find starts looking.
A fuller explanation of the find method is given in
string-methods
Example output:
Enter the name: George Washington
GEORGE WASHINGTON
17
r
Gexrge Washingtxn
George Washington
Count = 4
a found at 13
a found at 16
a found at 28
a found at 32
Add the following at the end of the script to show your results:
'''
Execution results:
paste execution results here
'''
Submit your finished py script in Canvas, Exercise B.