-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanipulation.py
More file actions
31 lines (23 loc) · 1.29 KB
/
manipulation.py
File metadata and controls
31 lines (23 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Ask the user to enter a sentence using the input() method. Save the user’s response in a variable called str_manip.
str_manip = input("Enter a sentence: ")
# Using this string value, write the code to do the following:
# ○ Calculate and display the length of str_manip.
print(f"Length of your sentence: {len(str_manip)} characters.")
# ○ Find the last letter in str_manip sentence. Replace every occurrence
# of this letter in str_manip with ‘@’.
# ■ e.g. if str_manip= “This is a bunch of words”, the output would
# be: “Thi@ i@ a bunch of word@”
print(f"Last letter in your sentence: {str_manip[-1]}")
print(
f"Replacing that character with @: {str_manip.replace(str_manip[-1], '@')}")
# ○ Print the last 3 characters in str_manipbackwards.
# ■ e.g. if str_manip= “This is a bunch of words”, the output would
# be: “sdr”.
print(
f"The last three characters in your sentence backwards: {str_manip[-1:-4:-1]}")
# ○ Create a five-letter word that is made up of the first three characters
# and the last two characters in str_manip.
# ■ e.g. if str_manip = “This is a bunch of words”, the output
# would be: “Thids”.
print(
f"The first three letters in your sentence then the last two letters, making a five-letter word: {str_manip[:3]}{str_manip[-2:]}")