For each of the following functions, specify the type of its return. You can assume each function is called with an appropriate argument, as specified by its docstring. If the output can be either an int or a float, select num, which isn't a real Python type, but which we'll use to indicate that either basic numeric type is legal. def b(x): x: int or float. return x + 1.0 Indicate the type of the output that the function b will yield. [Select] def d(x, y): x: Can be int or float. y: Can be int or float. return x > y Indicate the type of the output that the function d will yield. [Select] def f(x, y): x: int or float. y: int or float x + y - 2 Indicate the type of the output that the function f will yield. [Select]
Added by Esperanza F.
Close
Step 1
Is it due to limitations, constraints, or other factors? Show more…
Show all steps
Your feedback will help us improve your experience
Sri K and 59 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Create a python function probX(a,b) which for input values a and b with a ≤ b returns P(a < X < b). You do not need to worry what if a user enters values a and b such that a > b - you will only be tested at input values for which a < b. Set the default values of a and b to be a = float('-inf') and b = float('inf') which represent -∞ and ∞ in python. That is, float('-inf') is smaller than any numeric value, while float('inf') is larger than any numeric value. So, calling probX(a=1.2) should return the value P(1.2 < X < ∞) = P(X > 1.2). Also, calling probX(b=2.3) should return the value P(-∞ < X < 2.3) = P(X < 2.3) In addition, calling probX(1.2, 2.3) should return the value P(1.2 < X < 2.3) Hint: You can use your function F . Also, keep in mind that, say, value probX(1.2, 7) should be the same as probX(1.2, 3) . Note: float('inf') is equal to numpy.inf from numpy module, which is also equal to math.inf from math module; similarly is for float('-inf') . The reason why you were asked to set b=float('inf') rather than b=np.inf is simply because command b=float('inf') does not require importing any module, although numpy was imported (as np ) in this notebook, for other purposes.
Sri K.
This HW deals primarily with loops and functions. It will introduce you to some interesting number theory as well. You have probably heard of prime numbers and composite numbers before, but have you ever heard of abundant numbers or narcissistic numbers? This assignment will ask you to write code to identify different kinds of number properties. We also want you to learn how to reuse code in this assignment by writing and using functions. This is a basic strategy for reducing complexity in a program. Why? Because things change, and if you have the same thing in several places, when you change one, you have to change all the others. And you can't always find them all! In order to reuse code, you must take common pieces of code and put them into functions. Failure to do so will result in loss of points. We also want you to add comments to your code and docstrings to your functions. You can assume that all inputs in this assignment will be positive integers. Each function has been defined for you, but without the code. See the docstring in each function (in the starter code) for more details on what the function is supposed to do and how to write the code. It should be clear enough. In some cases, we have provided hints and examples to get you started. ```python def isComposite(x): """Returns whether or not the given number x is composite. A composite number has more than 2 factors. A natural number greater than 1 that is not prime is called a composite number. Note, the number 1 is neither prime nor composite. For example: - Calling isComposite(9) will return True - Calling isComposite(22) will return True - Calling isComposite(3) will return False - Calling isComposite(41) will return False """ # your code here if x > 1: for i in range(2, x): if x % i == 0: return True else: return False ```
Program Specification Using Python, design a class named PersonData with the following member variables: - lastName - firstName - address - city - state - zip - phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following member variables: - customerNumber - mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a boolean. It will be set to true if the customer wishes to be on a mailing list, or false if the customer does not wish to be on a mailing list. Write appropriate accessor and mutator functions for these member variables. Next, write a program that demonstrates an object of the CustomerData class in a program. Your program MUST use exception handling. You can choose how to implement the exception handling. Start your program with a welcome message. Make sure to include comments in your program. Use good variable names. A good variable name is one that describes what is stored in it. "Subtotal" is a good variable name, while "x" is a weak one. Use correct indentation. Organize your non-object-oriented code into a main function. Use inheritance. Use exception handling. Use more than two methods in your program that demonstrate the class you created.
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD