Computer Science I for majors by James Tam |
This assignment will involve a Python program that will calculate the product of two numbers. It will prompt the user for the two numbers and display the result. The framework of the program has been provided for you and can be found in the official course directory under: /home/231/assignments/mini_assignment4/calculateProduct.py or via this [shortcut link]. You need to define a function called 'multiply()' that will take the two numbers entered by the user as arguments and return their product. Also the return value of this function should be assigned to a variable called 'product' which is then displayed.
The following is the framework code into which you will insert your own code:
# >>> insert your function definition here <<<
def start():
print("This program will multiply two numbers")
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# >>> insert your function call here <<<
print("%f * %f = %f" %(num1,num2,product))
start()
Aside from input()/print() and functions to convert types: str(), float(), int(), unless you are told otherwise, you will need to write your own code and cannot use other pre-written Python functions/methods.
Feature |
Marks |
Function 'multiply()' is called with the correct arguments (1 mark for call itself, 2 for each of the arguments) |
3 |
Return result of function called assigned to 'product' |
1 |
Header of function 'multiply()' is properly defined (named defined, two parameters) |
3 |
TOTAL |
7 |
Raw score | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Grade point | 4.0 | 3.7 | 3.3 | 3.0 | 2.5 | 2 | 1 | 0 |