Our parents told us that we must eat vegetables to be healthy. And it turns out, our parents were right! So, what else did our parents tell?
Our parents told us that we must eat vegetables to be healthy.
And it turns out, our parents were right!
So, what else did our parents tell?
def showInLines():
# Open the file STORY.TXT for reading.
with open("STORY.TXT", "r") as file:
content = file.read() # Read the entire file content.
sentences = content.split('. ') # Split into sentences based on '. '.
# Further process to correctly handle sentences ending with '?' or '!'.
final_sentences = []
for sentence in sentences:
# Split by '? ' if present, otherwise by '! '.
sub_sentences = sentence.split('? ') if '?' in sentence else sentence.split('! ')
final_sentences.extend(sub_sentences)
# Print each sentence on a new line.
for sentence in final_sentences:
print(sentence.strip()) # Remove leading/trailing whitespace.
Explanation:
The file STORY.TXT is opened in read mode using with open(). The file's content is read into a string and then split into sentences using split('. '). For sentences that contain ? or !, additional splitting is performed to ensure accurate sentence separation. Each sentence is subsequently printed on a new line after removing any extraneous whitespace with strip().
myStr[:4] extracts the first 4 characters, which are "MISS".myStr[-5:] extracts the last 5 characters, which are "SIPPI"."#" in between, resulting in "MISS#SIPPI".
event = "G20 Presidency@2023"
L = event.split(' ')
print(L[::-2])