Question

Python Language Create a module (1 mark) a) Create a function that takes three (3) arguments...

Python Language

Create a module (1 mark)

a) Create a function that takes three (3) arguments (1 mark)

i) Name it whatever you’d like (1 mark)

ii) It will return a dictionary with the following keys (1 mark)

(1) Error => gives error message or empty string if not (1 mark)

(2) Result => gives result or empty string if no result (1 mark)

b) Ensure that all three arguments are of String (str) datatype (1 mark)

i) Return an error if not the case (1 mark)

c) Determine which of the three arguments has the greatest string length (3 marks)

i) Return the result (1 mark)

d) Write the code that will automatically run your function created in Step 1)

a) if it is the MAIN module. (1 mark)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

=============================== python code as per the instruction given ===================

def MyFunction(arg1,arg2,arg3):#function fefined
myDict = dict()#dictionary defined
myDict['Error'] = 'Error Message'#default message
myDict['Result'] = 'Return result'#default message
error=''#stores error
result=''#stores result
  
# type checking---------------------------------------
if not type(arg1)==str:
error+='argument 1 is not a string '
if not type(arg2)==str:
error+='argument 2 is not a strng '
if not type(arg3)==str:
error+='argument 3 is not a string '
myDict['Error'] = error
  
# calculating result----------------------------------
if error!='':
myDict['Result'] = result
return myDict
len1 = len(arg1)
len2 = len(arg2)
len3 = len(arg3)
if len1>len2:
result = arg1
elif len2>len3:
result = arg2
else:
result = arg3
myDict['Result'] = result
return myDict
# main function entry point:
if __name__ == '__main__':
arg1 = 'arg1'
arg2 = 'argument2'
arg3 = 'arg3bro'
myDict = MyFunction(arg1,arg2,arg3)
print(myDict)
arg1 = 6
arg2 = 'argument2'
arg3 = 'arg3bro'
myDict = MyFunction(arg1,arg2,arg3)
print(myDict)

-------------------------------------------------------------------------------------------------------------------------------------

screenshots of the code and the output:

-------------------------------------------------------------------------------------------------------------------------------------

============================== end =====================================================

--------------------------------- PLEASE LIKE THE POST ----------------------------------------------------------------------------------
  
  
  
  

Add a comment
Know the answer?
Add Answer to:
Python Language Create a module (1 mark) a) Create a function that takes three (3) arguments...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys)...

    Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary ("puffin": 5, "corgi": 2, "three": 3) and the list ("three", "corgi"), your function should return {"corgi": 2, "three"...

  • "PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes...

    "PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes two parameters, the filename and an effect. c. Take a picture with the filename and effect. Use camera.effect to set the effect. Use help(PiCamera) to find the effects which you can apply. d. Create a second file use_camera.py. e. Import the take_picture_effect function from the camera_picture module. f. Prompt the user for the filename. g. Prompt the user for the image_effect. help(PiCamera) to see...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function named capital_letter that accepts a string as an argument and checks if each word in the string begins with a capital letter. If so, the function will return true, otherwise, return false. Please see the outcome below: Outcome number 1: Enter a string: Python Is Really Fun! True Sample run number 2: Enter a string: i Love Python False Note: Try to keep this...

  • PYTHON 3: Write a function removeRand() that takes a dictionary d and an integer n as...

    PYTHON 3: Write a function removeRand() that takes a dictionary d and an integer n as parameters. The function randomly chooses n key-value pairs and removes them from the dictionary d. If n is greater than the number of elements in the dictionary, the function prints a message but does not make any changes to d. If n is equal to the number of elements in d, the function clears the dictionary. Otherwise the function goes through n rounds in...

  • Python 3 Write a function named starCounter that takes three parameters: 1. a dictionary named starDictionary....

    Python 3 Write a function named starCounter that takes three parameters: 1. a dictionary named starDictionary. Each key in starDictionary is the name of a star (a string). Its value is a dictionary with two keys: the string 'distance' and the string 'type'. The value associated with key 'distance' is the distance from our solar system in light years. The value associated with key 'type' is a classification such as 'supergiant' or 'dwarf'. 2. a number, maxDistance 3. a string,...

  • Create a function, myProd(), that takes two arguments, x and y, and multiplies the two arguments...

    Create a function, myProd(), that takes two arguments, x and y, and multiplies the two arguments together then adds 14 to the result. Finally, divide the sum by two and return as z I cannot come up with a solution for the above question, Could I get an explanation on how to approach and solve this problem. Thank you, I) Create a function, myProd), that takes two arguments, r and y, and multiplies the twoarguments together then adds 14 to...

  • PYTHON please -Create a function that takes a character chain and returns a histogram in a...

    PYTHON please -Create a function that takes a character chain and returns a histogram in a dictionary format. • The main program must take a dictionary and display it in alphabetical order. Note d.get(val1, val2) will return the value of the key val1 from dictionary d, otherwise val2. If we try to access directly d[val1], we get an error if key val1 does not exist.

  • Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings...

    Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings as a parameter. The strings are intended to represent a person's first and last name (with a blank in between). Assume the last names are unique. The function should return a dictionary (dict) whose keys are the people's last names, and whose values are their first names. For example: >>> dictionary = names([ 'Ljubomir Perkovic', \ 'Amber Settle', 'Steve Jost']) >>> dictionary['Settle'] 'Amber' >>>...

  • Using python, Write a function max3 that takes three numbers as its arguments and returns the...

    Using python, Write a function max3 that takes three numbers as its arguments and returns the greatest of these three numbers. Your submitted file for this problem should include (a) function definition, obviously, and (b) the code that calls that function (for this problem you do not have to package that calling code into the main() function although you may if you want to), so that if I run your *.py file it computes and prints something (e.g. few test...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT