Binayakarki (IPPS Workshop6)
Binayakarki (IPPS Workshop6)
Binayakarki (IPPS Workshop6)
A Python function “avg” returns the average of three values, as shown below:
n1 = 37, n2 = 108, n3 = 67
Define the function and variable declarations given above in the IDLE shell and execute the
following expressions. Which of the statements are valid?
Note down the response to each. Do they differ from what you would expect?
Ans: invalid, because avg function will expect 3 arguments, It will raise TypeError
Ans: Valid, all the variables pass as an argument are declared and also passing 3 arguments to the
function avg.But to get the result we need to print it or we can pass it to another variable and print
that.
Ans: Not valid (variables n5 and n6 are not declared) it will raise NameError
(D) print (avg (n1, n2, n3))
Invalid, because n3, n4,n5 are not declared . it they were declared then the way value is passing to
function is correct.
PART 2
Define a function
1. types () that prints a given value both as a float and an integer
4. hello_world( ) that takes a parameter name and displays the following output to the
console: "Hello World, my name is name".
5. improved_average( ) that takes five integer parameters. It should return the mode,
median and mean values of the numbers passed to the function.
PART 3
1. Create a function that prompts the user for two integer values and displays the results of
the first number divided by the second to two decimal places.
2. Create a Python program called calculator with functions to perform the following
arithmetic calculations, each should take two decimal parameters and return the result
of the arithmetic calculation in question.