1. Open idle. Click file, then click new file. This creates a new file.
After creating a new file, we enter the first line of code and use the print function to print a sentence on the screen. The string must use double quotes and the input method must use English. Input method, if symbols are entered using the Chinese input method, an error will occur. print("Let's do a calculation problem of adding two integers!")
Similarly, print the second sentence on the screen to interact with the user and remind the user Enter the first number.
The third line calls the input function and assigns the content entered by the user to a. At this time, a receives string information, so the next step is to convert the string. is an integer. This enters instructions for the computer to process the data.
Then follow the above steps to write the second addend and the final output sum. Note that when the last sentence prints the result, the quotation marks are in string form, and x y is a numerical value. form, so you need to add a comma in the middle. If you do not add a comma, an error message will be prompted. The above is the completion of all program writing. The next step is to save, name, and run. As shown in the figure
The running results are as follows:
For more Python related technical articles, please visit Learn in the Python tutorial column!
The above is the detailed content of How to write an adding calculator using python programming. For more information, please follow other related articles on the PHP Chinese website!