- Saved searches
- Use saved searches to filter your results more quickly
- constantkek/console-calculator-on-python
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Простой калькулятор на Python
- Консольный калькулятор на Python:
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
This is my project of a console calculator I’ve made using python
constantkek/console-calculator-on-python
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This is my project of a console calculator I’ve made using python
The program stores in calc.py file.
- Operator — stores the function you chose for a calculation
- Logger — works with saving calculations in a log.txt file.
- MyCalc — calculator itself
- init() — sets string to store
- askUser() — asks your preference to store value
- saveInFile(string) — appends the string to log.txt file and returns first line for testing
- start() — outputs welcome message in terminal
- calculate() — main function. Makes a calculations. Peep-beep-boop-peep-peep.
- add(nums) — adds all numbers and returns final string
- sub(nums) — subtract all numbers from nums[0]
- mult(nums) — multiplies all numbers and returns final string.
- divide(nums) — divide all numbers from nums[0]
- mod(nums) — calculate the modification of numbers
- askForInput() — asks you to type numbers, checks input to be numerical
- isCalcAgain() — asks you to calculate again
- askForLog() — asks you whether you want to store calculation
About
This is my project of a console calculator I’ve made using python
Простой калькулятор на Python
В этой статье мы разберём самый простой калькулятор на языке программирования Python, тут стоит сказать, что эта статья подойдёт совсем новичкам, так как сделаем обычный консольный калькулятор, профессиональным или просто опытным она не нужна.
Ещё можете посмотреть статью «Парсер страниц на Python», тоже очень полезна новичкам.
Консольный калькулятор на Python:
Как говорилось выше, мы сделаем легкий калькулятор на Python, и для этого нам нужно создать только один Python файл, я его назову «main.py».
Внутри него создадим функцию которая будет за всё отвечать, вот примерно так:
То есть мы создаём функцию где происходит вся логика, внутри неё первым делом выводим сообщение, что мы открыли калькулятор.
Потом запускаем бесконечный цикл и в нём даём выбрать действие, тут как обычно, то есть, если выбираем знак плюса, то будем складывать и т.д..
После идёт проверка команд, если выбрать кнопку «q», то выходим из программы, если же это арифметический знак, то вводим два числа, кладём их в переменные в формате числа с плавающей точкой.
Потом проверяем конкретный знак, зависимо от него и делаем действии, выводим на экран, самое интересное это с делением, мы делаем проверку, если делитель, то есть «y», равен нулю то тогда не будем делить.
Последние что осталось это объявить переменную, вот: