In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about how to achieve digital summation in Python. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
1. Open the IDLE,File--New File of python and create a new file
2. Enter the code in the empty file, File--Save, or Ctrl+s to save the file anywhere on the computer, press the keyboard F5 directly, or Run--Run Module to execute the code.
3. When running, enter the first number and then press the keyboard enter key, then enter the second number and press the keyboard enter key to get the following result:
Second, code analysis
Num1=input ("enter first number:")
Input is the function of waiting for user input, and the number entered by the user is assigned to num1.
Sum=float (num1) + float (num2)
Convert the num1 and num2 entered by the user into floating point (float) values, that is, numbers with decimal points, so that they can be calculated correctly regardless of whether they are integers or decimals.
Print ("numbers {0} and {1} add up to: {2}" .format (num1,num2,sum)
Print is the output, format is the formatted output, and {0}, {1}, and {2} correspond to the first parameter, the second parameter, and the third parameter in format in turn.
For example, enter the first number: 2.2, enter the second number, 1.3
Output: the numbers 2.2 and 1.3 add up to 3.5
Code Editing points for attention
1. When entering each line of code, each line must be aligned, and if there are spaces, the number of spaces must be the same.
2. Pay attention to the double quotation marks, which must be entered in the English input method, not in the Chinese input method, otherwise the program will run with an error.
After reading the above, do you have any further understanding of how to achieve digital summation in Python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.