Lab3 - People Server at UNCW

advertisement
Lab 3
Name_________________________
Today we demonstrate to the world, your ability to write a Python Program with multiple functions and
parameters!!!!
Write a Python program with the following functions:
sum3(a,b,c) :
This function has 3 parameters.
It sums the three numbers.
Prints “A+B+C= X.” Where A-C are the three values passed.
Calls the average function to calculate and print the average.
average(a,b):
This function has 2 parameters.
Calculates the average.
Prints “The average of the N numbers is X.” N indicates how many numbers there were. Allow
2 decimal places for X.
sum4(a,b,c,d):
This function has 4 parameters.
Adds the four numbers.
Prints “A+B+C+D= X.”
Calls the average function to calculate and print the average.
main() :
Asks the user for 3 numbers.
Calls the sum3() function passing the input values.
Asks the user for 4 more values.
Calls the sum4() function passing the input values.
If you still have time, try this:
remain():
Has 2 parameters.
Calculates the remainder when the 1st is divided by the 2nd without using the “remainder
operator.
Prints “The remainder when X is divided by Y is Z.”
Modify main() to ask for the values and pass them to remain()
Make sure you use comments to describe the program and the functions.
Use meaningful variable names.
Attach your program to the Lab3 Assignment in Blackboard.
Download