Coventry University Logo
4061CEM - Programming and Algorithms 1
  • Python Operators
    5

Python Operators

Before you attempt this activity, it is best that you review lecture video three from week two. 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

For this task, you will be testing your knowledge on arithmetic and in particular the process of calculating interest. You are required to provide an equation that will calculate the interest earned on a principal figure over a defined period of time for a set interest rate. The values and variables are defined below:

Variable Definition Value
\(p\) The principal amount. £10,492
\(t\) The length of time. 7 Years
\(r\) The rate of interest. 0.025%

Task 2

For this task, you will be testing your knowledge on arithmetic and assigning the result of an equation to a variable. To complete this task, you will need to answer the series of questions below, providing a solution in Python.

  1. Write an equation:
    • to calculate 8 to the power of 4
    • to calculate the sum of 5 and 6, multiplied by the exponent of 9 and 3
    • that finds the remainder of 87 divided by 8

Task 3

For this task, you will be using the assignment operator ('\(=\)') in conjunction with an arithmetic operator to provide a solution to these questions:

  1. Declare two variables \(x\) and \(y\) with the values \(10\) and \(20\), respectively. Then provide a solution to the following problems:
    • Add 20 onto the variable \(x\)
    • Subtract 10 from the variable \(y\)
  2. Declare a third variable \(z\) with the value \(5\)
    • Redeclare variable \(x\) with a division by variable \(z\)
Hint

For this task you are expected to use notation similar to \(*=\) to solve the problems above.

Task 4

For this task, you will be using the comparison operators. You are required to provide solutions that would satisfy the questions provided below.

  1. Declare a variable \(x\) and have it evaluate to True when variable \(a\) is less than \(10\)
  2. Declare a variable \(y\) and have it evaluate to False when variable \(a\) is greater than or equal to \(5\)
  3. Declare a variable \(z\) and have it evaluate to True when \(a\) is greater than or equal to \(5\)
Hint

For this task you are expected to use the same value for \(a\) to solve each of the equations above.

Task 5

For this task, you are required to answer the following questions with an appropriate solution:

  1. Declare variables \(x\) and \(y\) to be \(10\) and \(50\), respectively.
    1. Write an expression that checks whether \(x\) and \(y\) are the same object
    2. Write an expression that checks whether \(x\) is less than \(20\), and \(y\) is equal to \(x\)