Coventry University Logo
4061CEM - Programming and Algorithms 1
  • Conditional Statements
    2

Conditional Statements

Before you attempt this activity, it is best that you review lecture video two from week five. You can find the video and slides on the module page.

For this activity you will be using the integrated development environment recommended by the module leader. If you need to set up your development environment, it is recommended that you check out the instructions from activity four of week one.

Are You Struggling?

If you have trouble with any of the tasks or want to check your answers are correct, then please make yourself known to a member of staff.

Task 1 - Factorial Numbers

For this task, you need to write a function that will calculate the factorial of a number (the number must be a non-negative). The function will accept the number as an argument and return the factorial.

If you are struggling with this task, you may want to read up on factorial numbers.

Hint

For this task you will need to use a conditional statement to aid in the solution for this function.

Task 2 - Temperature Conversion

For this task, you need to write a function to convert temperatures to and from celsius and fahrenheit. You will want to consider that the input will be either 45F or 12C etc. The function will be called temperature_conversion.

Hint

For this task you will want to consider the following equation:

\(C = (5 / 9) \cdot (F - 32)\)

You may also assume that the temperature being using in this equation is an integer.