Exercise:03 Introduction to python

 

Python as a calculator

Python is perfectly suited to do basic calculations. Apart from addition, subtraction, multiplication, and division, there is also support for more advanced operations such as:

  • Exponentiation: **. This operator raises the number to its left to the power of the number to its right. For example 4**2 will give 16.
  • Modulo: %. This operator returns the remainder of the division of the number to the left by the number on its right. For example 18 % 7 equals 4.

The code in the script gives some examples.


Instructions
100 XP

Suppose you have $100, which you can invest with a 10% return each year. After one year, it's 100*1.1=110100×1.1=110 dollars, and after two years it's 100*1.1*1.1=121 100×1.1×1.1=121. Add code to calculate how much money you end up with after 7 years, and print the result.

Comments