Question

Hello all. I have 3 questions concerning something in python and I wanted to make sure...

Hello all. I have 3 questions concerning something in python and I wanted to make sure I was correct seeing as to how this is my first python class.

Consider the following code here:

def make_plot(data, x_values, y_values, save_file=True):

We just have to be able to point out the arguments, optional arguments, and required arguments.

I think the arguments are : data, x_values, y_values, save_file = True

I think the optional argument is: save_file = True

Am I correct so far about the arguments and optional arguments? I'm not sure what the required arguments are. Any help identifying the arguments, optional arguments, and required arguments would be greatly appreciated.

Homework Answers

Answer #1

Functions can have required and optional arguments.

def make_plot(data, x_values, y_values, save_file=True):

In the above function declaration the arguments are 'data, x_values, y_values, save_file=True'

The required arguments are 'data, x_values, y_values' .

The optinal arguments are 'save_file=True'

For optional arguments the default value is assigned by using assignment(=) operator of the form keywordname=value.For required arguments we don't need any default value to be assigned.

For your clarification i have provided one example below:

def f(required_arg, optional_arg1 = "1"):
#Create function with optional argument `optional_arg1`

print(required_arg, optional_arg1)

f("a")
#Call `f` using default value for `optional_arg1`

f("a", "b")
#Call `f` using `"b"` for `optional_arg1`

OUTPUT:

a 1
a b

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
Hello, I have a finance question I am confused on. A stock just paid a dividend...
Hello, I have a finance question I am confused on. A stock just paid a dividend of $2.71. The dividend is expected to grow at 28.38% for five years and then grow at 4.69% thereafter. The required return on the stock is 13.76%. What is the value of the stock? (Round to 2 decimals) It says the correct answer is $77.01 but I am having trouble trying to reach it. Any help would be greatly appreciated!
In python: I am trying to construct a list using enumerate and takewhile from a Fibonaci...
In python: I am trying to construct a list using enumerate and takewhile from a Fibonaci generator. So far the code I have is the following: def fibonacci(): (a, b) = (0, 1) while True: yield a (a, b) = (b, a + b) def createlist(n, fib): return [elem for (i, elem) in enumerate(takewhile(lambda x: x < n, fib)) if i < n] I only get half the list when I do: print(createlist(n, fibonacci())) Output: [0, 1, 1, 2, 3,...
Hello! I am coding in c# and I am having trouble using boolean variables and if...
Hello! I am coding in c# and I am having trouble using boolean variables and if statements. The project I am working on is based on the users input, and the code should branch into two different options. However, I am struggling to understand how to take the users input to decide which path to take. Another problem I am having is with my if statements. After the user has inputed information and the code decides to take them down...
I am working on exercise 5.30 from Introduction to Computing using python (Author: Perkovic). I was...
I am working on exercise 5.30 from Introduction to Computing using python (Author: Perkovic). I was looking at the solution and was able to understand what to do. However, when I implement the temp function as indicated, I keep getting this error "ValueError: the first two maketrans arguments must have equal length". However, it seems my two arguments are equal length, so I'm not sure what I am doing wrong! print('Exercise 5.30') def many(file): infile = open(file) content = infile.read()...
I had to make a calibration curve for the bradford dye-binding assay. My professor wanted us...
I had to make a calibration curve for the bradford dye-binding assay. My professor wanted us to fit the data to three different mathematical functions: a straight line in the form of y=mx+b, a second-order polynomial: y=a.x2+b*x+c a rectangular hyperbola on the form:y=(a*x)/(b+x) my results (I used the SciDavis program): y=0.0526X+0.0353 y=0.00987+0.063X-0.000537x2 y=(5.07X)/(76.3+x) I am supposed to use the graph i made to estimate the concentration of protein in my bacterial extract. So we set up 3 tubes of our...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
I'm working in a 6 page research paper and below is the complete list of the...
I'm working in a 6 page research paper and below is the complete list of the paper has to be set up and the required things needed to be included. Can you check to see what is already included on the list and what is missing in my paper. Also, what I need to improve and how? My topic is "The Struggles of Epilepsy". Can you help me with the content (background, empirical research, and hypothesis )? I also need...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT