Enkel Kalkulator

Skip to content

This doth be a machine-wrought text which may contain errors!

Vanskelighetsgrad: Easy

Compose a programme that doth beseech the user for two numbers. (Recall the input() function!) Thereafter, shalt thou add these together and then print the result unto the user. ‘Tis well to set it forth as 2 + 4 = 6.

Doth thou obtain the answer thou didst expect? Wherefore, or why not?

Hint!

Thou must convert to numbers by writing int() or float() (decimal numbers).

Hark, and prithee, set forth also these reckonings:

  • a - b (to subtract, good sir)
  • a * b (multiplication, as ‘twere)

Hark! An Extra!

  • Add code to print the division. a / b.
    • What doth occur when b is naught? Add a fix that doth check if the second number be 0.
  • Amend thy code to possess four functions, one for each operation. Move the logic from yore within here.
  • Ask the user for an “operation” betwixt the two numbers (+, -, *, /), then perform the calculation with the functions and print the answer!
  • Amend the code to ask for numbers and operations until the user doth say "stop", then print the answer to the whole operation.

Hint!

Employ a for-loop and a list [] to achieve this!