Python 1.4

Python as a calculator

  • Fully automatically graded on code quality, style, structure and functionality
  • Students write their solution in an online IDE in their LMS
  • Check for Python code plagiarism

Pre-requisites:

  • To have Python installed or use CodeGrade’s editor.
  • To have learned about print statements.

Learning goals:

  • Get familiar with Python arithmetics.
Get access to an autograder, plagiarism checker and online IDE for this assignment now!

Task:

Historically, computers were used to execute complex mathematical calculations. One of the first substantial computers was also called ENIAC: Electrical Numerical Integrator and Calculator (read more here!). Just like all programming languages, Python can still serve as a calculator. Understanding how to do arithmetics with Python is vital for almost all your upcoming Python projects too.

You will explore Python as a calculator. We will go over the following basic operations:

  • Addition `+`: E.g. `4 + 1 = 5`.
  • Subtraction `-`: E.g. `4 - 1 = 3`.
  • Multiplication `*`: E.g. `4 * 3 = 12`.
  • Division `/`: E.g. `12 / 4 = 3`.
  • Exponentiation `**`: Raise the number to the left to the power of the number to the right, e.g. `4**2 = 16`.
  • Modulo `%`: The remainder of the division of the number to the left with the number to the right, e.g. `16 % 3 = 1`.

Your task is to explore these operations. Write a program called `calculations.py` that prints the answers to the following in order:

  1. 120 + 43
  2. 9382 - 450
  3. 999 * 9994
  4. 120 / 40
  5. Calculate the answer to these problems:
    a. A team of hungry programmers share 50 slices of pizza. If each programmer eats exactly 3 pieces of pizza, how many slices are left over in the end?7
    b. Guido earns $30.000 in his first year as a software engineer. Each year, he gets a 3.5% raise. What is Guido’s salary after 5 years? (Learn more about exponential growth here)

The aim of this assignment is to explore arithmetics in Python. All you have to do is put these static calculations in `print` statements. Print everything on a new line using multiple prints.

Example usage:

-!- CODE language-bash -!-$ python3 calculator.py
163
8932
998001
3.0
...
...

Learn more:

Start teaching Python now

CodeGrade is your virtual teaching assistant for your coding classroom. You teach, CodeGrade takes care of the rest.

With our 40+ built-in fully automatically graded Introduction to Python assignments for university-level courses, you can start teaching Python at your institution with confidence now. Or, scale your classroom with CodeGrade's tools.

Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!

Book a demo now!

Happy educators

  • Educators who use CodeGrade have less stress.
  • Educators who use CodeGrade have happier and more successful students.
  • Educators who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.