-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson7_excercise_redi.py
More file actions
25 lines (19 loc) · 888 Bytes
/
lesson7_excercise_redi.py
File metadata and controls
25 lines (19 loc) · 888 Bytes
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
#Count the occurrences of the word ‘redi’ in the phrase: "ReDI school is awesome! Yes redi is really cool"
# a) Cut the sentence into two on the character ! Output the first part in lower case and the second part in uppercase
# b) Ask the user what word to use
redi_string = input('Please enter the string:')
#redi_string = " ReDI school is awesome! Yes redi is really cool "
sub_string = "REDI"
# convert string to lowercase
temp_str = redi_string.lower()
# use count function
count = temp_str.count(sub_string.lower())
print("The REDI count is:", count)
# cut the string into 2 pieces
length_of_word=len(redi_string)
half_the_length=int(length_of_word/2)
ex_mark_position=redi_string.find('!')
first_half=redi_string[0:ex_mark_position]
second_half=redi_string[ex_mark_position+1:length_of_word]
print(first_half.strip().lower())
print(second_half.strip().upper())