Computer Science I for majors by James Tam

Return to the course web page

CPSC 231: Mini-Assignment #4

Due October 27, at 4 PM

New Concepts to be applied for the assignment

Description

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.

Assignment Framework (duplicated from the code in the course directory for your convenience)

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()

Submitting your work:

  1. Assignments (source code/'dot-py' file) must be electronically submitted according to [the assignment submission requirements] using [D2L]
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].

Using pre-written Python libraries:

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.

Marking key

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

Determining your assignment mark: Mapping of Raw score to grade point

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