Basic Calculator
Goal
Build a simple Python program that can add, subtract, multiply, and divide two numbers.
Program Requirements
Ability to obtain/read two numeric inputs from the user of the program
Store/remember the two inputs
Do all the possible operations (add, subtract, multiply, divide) on the two numbers
Display the output
Pseudocode of the Calculator
Pseudocode 1: Basic Calculator
This program stores two inputs in two separate variables. Then it generates 4 more variables to store each of the resulting operation. Lastly, the program will output the stored operations to complete its execution.
A computer program is a set of instruction that a computer will follow to complete a given task; therefore, the computer will start from line 1 of the program, and it will execute all of the given instructions until the end of its instruction set.
Python Translation
This Python program above is a direct translation of our program designed as a pseudocode.
The
#
symbol is used to create comments; a way to leave readable notes for the reader, but an ignored line of code by the Python Interpreter.input()
is a that reads a typed text within the .int()
is a built-in function that converts a given into an integer.print()
is a built-in function that outputs text-based data (called a ) to the console.
Within our print()
function, we are outputting formatted strings or "f-strings".
f-strings
are special types of strings that allow the direct values of variables embedded via curly braces {}
and it maintains the format of the strings based on how the data was defined.
Example Program Output
Connected Reading
Connected reading is a section dedicated to provide fundamental knowledge to the important aspects introduced in this page.
Last updated