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 in read mode with open("STORY.TXT", "r") as file: content = file.read() # Read the entire content of the file sentences = content.split('. ') # Split by '. ' for sentences # Process further to handle '? ' and '! ' final_sentences = [] for sentence in sentences: sub_sentences = sentence.split('? ') if '?' in sentence else sentence.split('! ') final_sentences.extend(sub_sentences) # Print each sentence in a separate line for sentence in final_sentences: print(sentence.strip()) # Strip leading/trailing whitespacesExplanation: The file
STORY.TXT
is opened in read mode using the with open()
statement.
The content of the file is read into a string and split into sentences using split('. ')
.
For sentences containing ?
or !
, further splitting is done to ensure each sentence is correctly separated.
Each sentence is then printed on a new line after removing extra whitespaces using strip()
.
Write a user-defined function in Python named showGrades(S) which takes the dictionary S
as an argument. The dictionary S
contains Name: [Eng, Math, Science] as key:value pairs.
The function displays the corresponding grade obtained by the students according to the following grading rules:
\[ \begin{array}{|c|c|} \hline \textbf{Average of Eng, Math, Science} & \textbf{Grade} \\ \hline \geq 90 & A \\ \hline < 90 \text{ but } \geq 60 & B \\ \hline < 60 & C \\ \hline \end{array} \]
Example: Consider the following dictionary: \[ S = \{\text{"AMIT"}: [92, 86, 64], \text{"NAGMA"}: [65, 42, 43], \text{"DAVID"}: [92, 90, 88]\} \] The output should be: \[ \text{AMIT} - B \\ \text{NAGMA} - C \\ \text{DAVID} - A \]
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])
Read the following characteristics of retail trading carefully and choose the correct option:
I. This is concerned with the sale of goods directly to the consumers.
II. Most of the retail trading takes place in fixed establishments or stores.
III. It is formed by many middlemen, traders, and suppliers.
IV. Hawkers, street peddling, automatic vending machines, etc., are its examples.
Read the programmes related to the proposed Bharatmala umbrella scheme carefully and choose the correct option:
I. Backward areas, religious and tourist places connectivity programme
2. To interconnect the four metropolitan cities of the country
3. To develop State roads in adjoining coastal areas
4. To connect non-major ports in coastal states