Tutorial: Developing a simple calculator with basic command in python(fix bugs in your code)

in #utopian-io6 years ago (edited)

images.png
Repository: CPython

Objective : The objective of this tutorial is to develop a simple calculator using cpython. This would involve the code and certain common bugs that you could encounter with how to identify and fix them.
Note: This tutorial is for someone with a basic knowledge of python.

Software: Download here
(Find a version compatible with your system)

Code
Screenshot_20180627-143727_1530106792693.png
Screenshot_20180627-133746_1530106532311.png
Screenshot_20180627-133754_1530106579578.png

Tutorial
First things first you describe your code using the multiple line comment as seen at the beginning of the code.
Screenshot_20180627-143727_1530106792693_1530107906704.png

Then you define the functions add, subtract, multiply and divide seen in these lines of code.
Screenshot_20180627-143727_1530106792693_1530108079981.png
Screenshot_20180627-133746_1530106532311_1530108118726.png
In the next part of this code involves collecting variables and running these variables in the code. For this we use the if, elif and else function.
Screenshot_20180627-133754_1530106579578_1530108475258.png

Common bugs encountered
It is common to encounter a few bugs when you learn python with versions 2. and move to 3. programs such as cpython. One of these that can be seen in this code is the print function
Screenshot_20180627-143727_1530106792693_1530107707260.png
Another important thing to note is that the values collected have to be floated(i.e in decimal value) hence use the float function to change all input values to floats.
Screenshot_20180627-133754_1530106579578_1530108475258_1530108527489.png

Conclusion
CPython is by far the best version of python I've coded with and it's easy and understandable. Run this program and leave your comments in the comment section.

Sort:  

I thank you for your contribution. Here is my thought;

  • Tutorials should teach the user something unique, shouldn't show ubiquitous content-creation and replicate concepts which can be found over internet with great ease. Therefore, in the voting phase, your tutorial might not be considered.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

This tutorial was targeted for those starting up on the steemit platform who know the basic concepts but don't know how to apply them. However thanks for your thought.

Hello! I find your post valuable for the wafrica community! Thanks for the great post! @wafrica is now following you! ALWAYs follow @wafrica and use the wafrica tag!

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 62831.42
ETH 3123.16
USDT 1.00
SBD 3.85