Write a function, c_words(), in Python that separately counts and displays the number of uppercase and lowercase alphabets in a text file, Words.txt
def c_words():
# Open the file Words.txt in read mode
with open("Words.txt", "r") as file:
content = file.read() # Read the entire content of the file
upper_count = 0 # Initialize uppercase count
lower_count = 0 # Initialize lowercase count
# Iterate through each character in the content
for char in content:
if char.isupper(): # Check for uppercase letters
upper_count += 1
elif char.islower(): # Check for lowercase letters
lower_count += 1
# Display the counts
print(f"Uppercase letters: {upper_count}")
print(f"Lowercase letters: {lower_count}")
Explanation:
The file Words.txt is opened in read mode, and its content is read into a string.
The function iterates through each character in the file.
The isupper() method is used to check for uppercase letters, and the islower() method is used to check for lowercase letters.
Counts of uppercase and lowercase letters are maintained in separate variables and displayed after iteration.
\[ \begin{array}{|c|c|c|c|} \hline \textbf{S\_id} & \textbf{S\_name} & \textbf{Address} & \textbf{S\_type} \\ \hline S001 & Sandhya & Rohini & Day Boarder \\ S002 & Vedanshi & Rohtak & Day Scholar \\ S003 & Vibhu & Raj Nagar & NULL \\ S004 & Atharva & Rampur & Day Boarder \\ \hline \end{array} \]
\[ \begin{array}{|c|c|c|} \hline \textbf{S\_id} & \textbf{Bus\_no} & \textbf{Stop\_name} \\ \hline S002 & TSS10 & Sarai Kale Khan \\ S004 & TSS12 & Sainik Vihar \\ S005 & TSS10 & Kamla Nagar \\ \hline \end{array} \]
The SELECT statement when combined with \(\_\_\_\_\_\_\) clause, returns records without repetition.
In SQL, the aggregate function which will display the cardinality of the table is \(\_\_\_\_\_\).
myStr = "MISSISSIPPI"
print(myStr[:4] + "#" + myStr[-5:])