当前位置:网站首页>Realize the addition of all numbers between 1 and number
Realize the addition of all numbers between 1 and number
2022-07-05 13:01:00 【South Lake Fishing Song】
Write a function :
The name is called sum_numbers
There is a parameter called number
Within the function , Realization 1~number Between , Sum of all numbers
Print the result of the addition
Call this function many times , Introduce different number View results
# While loop
def sum_number(number):
''' MAS: Realization 1~number Between , Sum of all numbers '''
i = 1
sum_value = 0
while i < number + 1:
sum_value = sum_value + i
i = i + 1
print(number,' The result of addition is ',sum_value)
sum_number(100)
# for loop
def sum_number(number):
''' MAS: Realization 1~number Between , Sum of all numbers '''
sum_value = 0
for i in range (1,number + 1):
sum_value += i
print(number,' The result of addition is ',sum_value)
sum_number(100)
边栏推荐
- HiEngine:可媲美本地的云原生内存数据库引擎
- mysql拆分字符串做条件查询
- Reshape the power of multi cloud products with VMware innovation
- Natural language processing from Xiaobai to proficient (4): using machine learning to classify Chinese email content
- 函数的默认参数&函数参数的多种方法
- Taobao short videos are automatically released in batches without manual RPA open source
- 《信息系统项目管理师》备考笔记---信息化知识
- 逆波兰表达式
- Comprehensive upgrade of Taobao short video photosynthetic platform
- Transactions from December 27 to 28, 2021
猜你喜欢
SAP UI5 FlexibleColumnLayout 控件介绍
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
我在滴滴做开源
Setting up sqli lab environment
Introduction to the principle of DNS
Association modeling method in SAP segw transaction code
LeetCode20.有效的括号
Didi open source Delta: AI developers can easily train natural language models
PyCharm安装第三方库图解
leetcode:221. 最大正方形【dp状态转移的精髓】
随机推荐
石臻臻的2021总结和2022展望 | 文末彩蛋
155. 最小栈
DNS的原理介绍
谈谈我写作生涯的画图技巧
10 minute fitness method reading notes (5/5)
Compile kernel modules separately
Wechat enterprise payment to change access, open quickly
HiEngine:可媲美本地的云原生内存数据库引擎
初识Linkerd项目
mysql拆分字符串做条件查询
NFT: how to make money with unique assets?
初次使用腾讯云,解决只能使用webshell连接,不能使用ssh连接。
It's too convenient. You can complete the code release and approval by nailing it!
深度长文探讨Join运算的简化和提速
How to connect the API interface of Taobao open platform (super detailed)
I met Tencent in the morning and took out 38K, which showed me the basic smallpox
Why is your next computer a computer? Explore different remote operations
Transactions from December 27 to 28, 2021
ABAP editor in SAP segw transaction code
CVPR 2022 | single step 3D target recognizer based on sparse transformer