Home>Article>Backend Development> How to write an adding calculator using python programming

How to write an adding calculator using python programming

尚
Original
2019-07-03 15:40:38 11386browse

How to write an adding calculator using python programming

1. Open idle. Click file, then click new file. This creates a new file.

How to write an adding calculator using python programming

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!")

How to write an adding calculator using python programming

Similarly, print the second sentence on the screen to interact with the user and remind the user Enter the first number.

How to write an adding calculator using python programming

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.

How to write an adding calculator using python programming

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

How to write an adding calculator using python programming

The running results are as follows:

How to write an adding calculator using python programming

For more Python related technical articles, please visitLearn in the Python tutorialcolumn!

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn