PYTHON,
write a function that accepts a text file's name and returns
a. the number of uppercase letters in the file
b. the number of lowercase letters in the file
c. the number digits in file
d. the number of whitespace characters in the file
def file_stats(filename):
upper, lower, digits, whitespace = 0, 0, 0, 0
try:
with open(filename, 'r') as f:
data = f.read()
for ch in data:
if ch.islower():
lower += 1
elif ch.isupper():
upper += 1
elif ch.isdigit():
digits += 1
elif ch.isspace():
whitespace += 1
except FileNotFoundError:
pass
return upper, lower, digits, whitespace
print(file_stats('input.txt'))
PYTHON, write a function that accepts a text file's name and returns a. the number of...
Can someone help me with the following problems please! 6. Write a function that accepts a text file’s name and returns a. The number of uppercase letters in the file b. The number of lowercase letters in the file c. The number of digits in the file d. The number of whitespace characters in the file .
python question!
points) Attached to the Exam #4 code Assignment in Tracs you ## will find a file, "text.txt". Text is stored 1 sentence per line. ## Write a program below that reads the file contents and displays ## the following: ## 1. Number of uppercase characters in the file ## 2. Number of lowercase characters in the file ## 3. Number of digits in the file. ## 4. Number of whitespace characters in the file ## ## print("Number of...
i
need the answer for this python question using dictionary method
please!!!
points) Attached to the Exam #4 code Assignment in Tracs you ## will find a file, "text.txt". Text is stored 1 sentence per line. ## Write a program below that reads the file contents and displays ## the following: 1. Number of uppercase characters in the file 2. Number of lowercase characters in the file 3. Number of digits in the file. 4. Number of whitespace characters in...
You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python code that gets a string from the user and counts the number of uppercase letters, the number of lowercase letters, the number of digits, and the sum of the digits. Please see the outcome below: Outcome: Enter the string: okOKE9o7 Uppercase letters: 3 Lowercase letters: 3 Digits: 2 Sum of digits: 8 Must look exactly like outcome for full credit.
1. Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters. Sample String : 'The quick Brow Fox' Expected Output : No. of Upper case characters : 3 No. of Lower case Characters : 12
5. Write a Python function called readlinesmton that accepts the name of the file (i.e. filename), starting line number i.e. m) and ending line number (i.e. n) as a parameter. The function then returns the contents from line number m to n (m <n). If m < 1 then start from line 1. Similarly, if n > number of lines the file, then stop at the last line in the file. Sample Input: readlinesmton("data.txt",5,7) Sample Input: readlinesmton("data.txt", 0,10)
1. Write a function to keep asking the user for names in the form of strings, sort alphabetically and store these names into a text file named names.txt 2. Write a function that accepts a string as the argument, removes all alphabetical letters from the string, and returns it 3. Write a function that accepts a file name in the form of a string as the argument. Assume the text file contains single-digit numbers and letters. Read the entire contents...
PYTHON QUESTION PLEASE!!
Write a function named problem3 that accepts two strings as the
arguments, returns the characters that occur in both strings. Test
case: the arguments are “apple@123” and “banana@#345”, your program
should return “a@3”.
Write a function named problem3 that accepts two strings as the arguments, returns the characters that occur in both strings. (20 pts) Test case: the arguments are "apple@123” and “banana@#345”, your program should return "a@3".
Write a javascript function that accepts 3 arrays and returns a string of the elements sorted in ascending value, with duplicates removed. Return all alphabetic characters in lowercase. E.G. function([ 1,2,3, d], [5, 3, 0, ‘a’], [‘a’,’d’,9]) returns “0,1,2,3,5,9,a,d” E.G. function(['w', 'i', 'H', 5], [8, 5, 9, 'c', 'Z'], [6, 4, 'a', 'b', 'y']) returns “4,5,6,8,9,a,b,c,h,i,w,y,z” we must not use ' sort, remove, split,join and any built-in fucntions