event = "G20 Presidency@2023"
L = event.split(' ')
print(L[::-2])
'G20'
'Presidency@2023'
'G20'
'Presidency@2023'
<div class="question">
<strong>Question:</strong> The split() method divides the string "G20 Presidency@2023" into a list of substrings based on spaces, resulting in:
<pre><code>
L = ["G20", "Presidency@2023"]
</code></pre>
The slicing operation L[::-2] works as follows:
<ul>
<li>[::-2] reverses the list and selects every second element.</li>
<li>Starting from the end, L[::-2] picks "G20".</li>
</ul>
Thus, the output is: ['G20'].
</div>
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"
.Consider the following Python statement:
F = open('CONTENT.TXT')
Which of the following is an invalid statement in Python?
The correct IUPAC name of \([ \text{Pt}(\text{NH}_3)_2\text{Cl}_2 ]^{2+} \) is: