question archive What is a mutator method? Explain why mutator methods usually return the value None? Write loop that accumulates the sum of the numbers in a list named data? Write loop that replaces each number in a list named data with its absolute value? Describe the costs and benefits of aliasing, and explain how it can be avoided
Subject:Computer SciencePrice:4.86 Bought14
What is a mutator method? Explain why mutator methods usually return the value None?
Write loop that accumulates the sum of the numbers in a list named data?
Write loop that replaces each number in a list named data with its absolute value?
Describe the costs and benefits of aliasing, and explain how it can be avoided.?
Explain the difference between structural equivalence and object identity.?
What roles do the parameters and the return statement play in a function definition?
Use the function even to simplify the definition of the function odd presented in this section.?
Define a function named summation. This function expects two numbers, named low and high, as arguments. The function computes and returns the sum of the numbers between low and high, inclusive.?
What is the purpose of a main function?
Give three examples of real-world objects that behave like a dictionary?
Below is the answer mentioned:
Step-by-step explanation
[Note:
Python is indentation oriented language, so the codes given under must be indented. Please resolve your indentation error if you get in any case.]
Answer1:
First Part:
Mutator method can be defined as a process used to control changes to a specific variable. We use this method to modify the value of an instance variable. This method is also known as setter method.
Second Part:
Mutator method is used to modify the variable values. This method does not require to return any value. So, the return value of this method is none.
Answer 2:
# PYTHON: Code to loop that accumulates the sum of all of the numbers in a list named data.
total = 0
for x in data:
total += x
print(total)
Answer 3:
OUTPUT:
[1, 3, 5]
Answer 4:
Aliasing can make the different signals for becoming in-distinguishable from one another.
Aliasing can be reduced with the help of sampling, which is done at a higher rate than that of the Nyquist
rate.
Anti-aliasing technique is being used for eliminating the effect of overlaping of the frequency components.
Answer 5:
The object identity is meant for a situation where the structure of the object is not encapsulated. Here, the
2 objects are meant to be in the same object based on having the identical properties.
Structural equivalence is meant for extending the 2 specied nodes which are con
Answer 6:
in a function denition return statements play following roles:
The return statement stops the execution of a function and returns control to the calling function.
A return statement can also return a value to the calling function after executing the logic on input
parameters.
in a function denition parameters play following roles:
A parameter is a value that is passed into a function.
if any function is intended to compute on an outside value of the function then we will use parameters to
receive or accept information from outside sources or functions.
for example:
public class Function {
int add(int a,int b){
int c=a+b;
return c;
}
public static void main(String[] args) {
Function f=new Function();
int d=f.add(5,6);
System.out.println("The value is: "+d);
}
}
output:
The value is: 11
Here int a and int b are parameters which accept value.
Return statement will return the value after adding a and b back to the calling function.
Answer 7:
For odd function
if we divide an odd number by 2 remainder will be 1
condition for a number n to be odd (n%2 == 1)
The denition of the function odd()
def odd(n):
if n%2 == 1:
return True
return False
Answer 8:
# This function take two number parameters low and high and calculates
# sum of all numbers between low and high, inclusive.
def sum(low, high):
#Varaible to hold sum of integers
total=0
# Loop starts with low, ends with high and with step size(increment) 1
# range() function works this way.... range(0, n) gives 0,1,2,..n-1
# By default range() function takes step size as 1.
for i in range(low, high + 1):
# Adding each integer to existing sum
total += i;
# Returning total
return total
#Below statements are to test the sum function
#Below statements are to test the sum function
#For python 3, uncomment below code and comment the below mentioned print statements for python
2.x.x
#print("Low:1, High:10 and Sum of all numbers between low and high(inclusive):", sum(1, 10))
#print("Low:1, High:5 and Sum of all numbers between low and high(inclusive):", sum(1, 5))
#print("Low:5, High:10 and Sum of all numbers between low and high(inclusive):", sum(5, 10))
#For python 2.x.x
print "Low:1, High:10 and Sum of all numbers between low and high(inclusive):", sum(1, 10)
print "Low:1, High:5 and Sum of all numbers between low and high(inclusive):", sum(1, 5)
print "Low:5, High:10 and Sum of all numbers between low and high(inclusive):", sum(5, 10)
Answer 9:
It's the core of every program, main () function calls / invokes other functions within it. The execution of the program always starts from the main function.
The main function serves as the starting point for program execution. It usually controls program execution by directing the calls to other functions in the program. A program usually stops executing at the end of main.
Answer 10:
Dictionaries are used to map the information which we need to store to the keys which are
needed to get them. It is a collection of unordered data with key value pairs.
Example 1: Employee information storage.
In companies the employee information such as age, address, and salary can be stored using
dictionary. When we wanted to access the information of any particular employee we can use
Employee Id as the key.
employee={'111':{'Name':'John','age':24,'salary':10000},'222':
{'Name':'Joe','age':28,'salary':20000}}
Comment
In the example above, the Employee Id is the key and the values are the also dictionary that
stores the name, age and salary of the employee.
Example 2: Phone Book
Using the phone book dictionary one can easily access the phone number using the name
associated with it.
Phonebook ={ "John" : 9234555555, "Joe" : 9383838383, "Jack" : 9474794211}
In the example above, the phone number can be accessed using the name of the person.
Example 3: Address Book:
Using the address book dictionary we can store the address of the person by using name as the
key to access them.
AddressBook = { 'Jack' : "No 2, DownTown", 'Harry': "No 4, Michigan"}
In the example above, the address of the person can be accessed using the name of the person.
Please see the attached file for the complete solution