Question

In: Computer Science

(python) Write a function that involves two arguments, named changeTheCase(myFile, case),thattakes, as arguments, the name of...

(python) Write a function that involves two arguments, named changeTheCase(myFile, case),thattakes, as arguments, the name of a file, myFile, and the case, which will either be"upper"or"lower".If case is equal to "upper" the function will open the file, convert all characters on each line to upper case, write each line to a new file, named "upperCase.txt", and return the string "Converted file to upper case."If case is equal to "lower" the function will open the file, convert all characters on each line to lowercase, write each line to a new file, named "lowerCase.txt", and return the string"Converted file to lower case." If case is any other value, the function returns the string "Invalid parameter."

For example:

>>>changeTheCase("hello.txt","upper")

should open the file named hello.txt, convert each character in each line to upper case, write each converted line to a new file named upperCase.txt, close both files,

and return the string "Converted file to upper case." As another example:

>>>changeTheCase("hello.txt", "lower")

should open the file named hello.txt, convert each character in each line to lower case, write each converted line to a new file named lowerCase.txt, close both files,

and return the string "Converted file to lower case." As a final example:

>>>changeTheCase("hello.txt","yibbie")

should return the string"Invalid parameter."

Solutions

Expert Solution

def changeTheCase(name,case):
try:
#opening the file
#takes 2 args
#name and mode
# r - read mode
f = open(name, "r")
f1= open("upperCase.txt", "w")

except IOError:
print ("Error: can\'t find file or read data")
  
for x in f:
#checking if it is upper than converting to upper and writing to file
if case=="upper":
x=x.upper()
else:
x=x.lower()
f1.write(x)
f.close()
f1.close()
print("Converted Successfully...!!!")

changeTheCase("myfile.txt", "upper")

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

(In python) 4. Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as...
(In python) 4. Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as arguments, the name of a file, myFile, and the case, which will either be “upper” or “lower”. If case is equal to “upper” the function will open the file, convert all characters on each line to upper case, write each line to a new file, named “upperCase.txt”, and return the string “Converted file to upper case.” If case is equal to “lower” the function...
write a python program that include a function named activity_selection() and take in two arguments, first...
write a python program that include a function named activity_selection() and take in two arguments, first one would be the number of tasks and the second argument would be a list of activities. Each activity would have an activity number, start time and finish time. Example activity_selection input and output: activity_selection (11, [[1, 1, 4 ], [2, 3, 5], [3, 0, 6], [4, 5, 7], [5, 3, 9], [6, 5, 9],[7, 6, 10], [ 8, 8, 11], [ 9, 8,...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values (but not necessarily in the same order), otherwise it returns 0. Your solution must not sort either array or a copy of either array! Also you must not modify either array, i.e., the values in the arrays upon return from the function must be the same as when the function was called. Note that the arrays do not...
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
Write code to define a function named mymath. The function has three arguments in the following...
Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Integer. It returns an Integer. The function will return a value as follows: 1. If the Boolean variable is True, the function returns the sum of the two integers. 2. If the Boolean is False, then the function returns the value of the first integer - the value of the second Integer.
Using Python #Write a function called after_second that accepts two #arguments: a target string to search,...
Using Python #Write a function called after_second that accepts two #arguments: a target string to search, and string to search #for. The function should return everything in the first #string *after* the *second* occurrence of the search term. #You can assume there will always be at least two #occurrences of the search term in the first string. # #For example: # after_second("11223344554321", "3") -> 44554321 # #The search term "3" appears at indices 4 and 5. So, this #returns everything...
Language: Python 3 (Please structure answer as basic as possible) Write a function that involves two...
Language: Python 3 (Please structure answer as basic as possible) Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as arguments, the name of a file, myFile, and the case, which will either be “upper” or “lower”. If case is equal to “upper” the function will open the file, convert all characters on each line to upper case, write each line to a new file, named “upperCase.txt”, and return the string “Converted file to upper case.” If...
ON PYTHON: a) Write a function named concatTuples(t1, t2) that concatenates two tuples t1 and t2...
ON PYTHON: a) Write a function named concatTuples(t1, t2) that concatenates two tuples t1 and t2 and returns the concatenated tuple. Test your function with t1 = (4, 5, 6) and t2 = (7,) What happens if t2 = 7? Note the name of the error. b) Write try-except-else-finally to handle the above tuple concatenation problem as follows: If the user inputs an integer instead of a tuple the result of the concatenation would be an empty tuple. Include an...
On Python: a) Write a function named concatTuples(t1, t2) that concatenates two tuples t1 and t2...
On Python: a) Write a function named concatTuples(t1, t2) that concatenates two tuples t1 and t2 and returns the concatenated tuple. Test your function with t1 = (4, 5, 6) and t2 = (7,) What happens if t2 = 7? Note the name of the error. b) Write try-except-else-finally to handle the above tuple concatenation problem as follows: If the user inputs an integer instead of a tuple the result of the concatenation would be an empty tuple. Include an...
Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT