Question

Write a Python function that takes a filename as a parameter and returns the string 'rows'...

Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).

Homework Answers

Answer #1

Code explaination :

We have created function that takes a filename as parameter and returns row if file is written row by rows else returns columns

#function defined
def myfunc(filename):
openFile = open("example.txt", "r")
fileData = openFile.read()
rowData = fileData.split("\n")
rowCount = 0
for a in rowData:
if a:
rowCount += 1
# if row count is more than 1 then it returns rows 
if rowCount > 1:
return "rows"
#else it will return column
else:
return "columns"
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
write a function call character_thing (string, character) that takes in a string and a character. The...
write a function call character_thing (string, character) that takes in a string and a character. The function will return the number of times the character appears in the string. please be in python
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
Python. create a function that takes a string as a parameter and prints out the following...
Python. create a function that takes a string as a parameter and prints out the following details as the example output below. If the string is "Hello, my name is Starling, Clarice. My, my, my, nice to meet you." The output would be: Unique words: 10 Number of commas: 5 Number of periods: 2 Number of sentences: 2 (HINT: Use the following string methods: split, lower, count, replace, format, and use the following functions: set, len. You may need to...
Write Java code that attempts to call a method named bootUp() which takes a String parameter...
Write Java code that attempts to call a method named bootUp() which takes a String parameter and returns an integer value. The String parameter should be read from a file named "bootConfig.txt" and is the only value in the file. If a BootUpException is thrown, print the Exception object's message. If a DriverException occurs, call the reboot() method and rethrow the original DriverException object. If any other type of Exception is thrown, print a generic error message to the console....
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns a 2D array of integers of size rows x cols where the value of element [row][col] is row + col. Write a short program to test your method.
Write a Scheme function that takes a simple list of numbers as a parameter and returns...
Write a Scheme function that takes a simple list of numbers as a parameter and returns a list with the largest and smallest numbers in the input list.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT