- Python Projects for Kids
- Jessica Ingrassellino
- 234字
- 2021-07-09 19:35:13
Basic functions
We learned at the beginning of this chapter that the first electronic calculator had four basic functions: addition, subtraction, multiplication, and pision. We will be working on programming each of these functions, and we will also learn a fifth mathematical function that we can program for our calculator called modulo.
Through the beginning of this chapter, we will use the addition()
function as our example. Once we have created and tested an addition()
function that does what we want it to, we will then build our other functions.
Let's return to our example of the addition function in Chapter 2, Variables, Functions, and Users. Recall how we programmed this function:

The addition function in the preceding screenshot does perform proper addition and prints the answer. However, there are problems with designing an addition()
function this way. One problem is that the program can only add the same two numbers over and over again. Another problem is that, in this program, we are only using one mathematical operation (addition). This addition()
function is too inflexible on its own; we need to design a function that is more user friendly.
To design a better mathematical function, we need to solve the problem of user-inputs by letting the user change the numbers in the calculation. We also need to design a calculator where the user has mathematical functions other than addition that can be performed.
- Qt 5 and OpenCV 4 Computer Vision Projects
- AngularJS Testing Cookbook
- Rake Task Management Essentials
- Java從入門到精通(第4版)
- Implementing Cisco Networking Solutions
- 鋒利的SQL(第2版)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲案例實戰(zhàn)全流程詳解(高級進(jìn)階篇)
- 利用Python進(jìn)行數(shù)據(jù)分析(原書第3版)
- Linux Device Drivers Development
- iOS開發(fā)實戰(zhàn):從入門到上架App Store(第2版) (移動開發(fā)叢書)
- C++從入門到精通(第5版)
- 深度學(xué)習(xí):Java語言實現(xiàn)
- Go語言精進(jìn)之路:從新手到高手的編程思想、方法和技巧(2)
- Swift 4從零到精通iOS開發(fā)
- C陷阱與缺陷