当前位置:网站首页>实现 1~number 之间,所有数字的加和
实现 1~number 之间,所有数字的加和
2022-07-05 12:40:00 【南湖渔歌】
编写一个函数:
名字叫做 sum_numbers
有一个参数叫做 number
函数内,实现 1~number 之间,所有数字的加和
打印加和的结果
调用多次这个函数,传入不同的number查看结果
# While 循环
def sum_number(number):
''' MAS:实现 1~number 之间,所有数字的加和 '''
i = 1
sum_value = 0
while i < number + 1:
sum_value = sum_value + i
i = i + 1
print(number,'加和的结果是',sum_value)
sum_number(100)
# for 循环
def sum_number(number):
''' MAS:实现 1~number 之间,所有数字的加和 '''
sum_value = 0
for i in range (1,number + 1):
sum_value += i
print(number,'加和的结果是',sum_value)
sum_number(100)
边栏推荐
- Annotation problem and hidden Markov model
- Storage Basics
- SAP 自开发记录用户登录日志等信息
- JDBC -- use JDBC connection to operate MySQL database
- Full text search of MySQL
- 超高效!Swagger-Yapi的秘密
- Taobao short videos are automatically released in batches without manual RPA open source
- 我在滴滴做开源
- I'm doing open source in Didi
- 自然语言处理系列(一)入门概述
猜你喜欢
stm32和电机开发(从架构图到文档编写)
Setting up sqli lab environment
Iterator details in list... Interview pits
Annotation problem and hidden Markov model
太方便了,钉钉上就可完成代码发布审批啦!
【云原生】Nacos中的事件发布与订阅--观察者模式
我在滴滴做开源
Storage Basics
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
自然语言处理系列(一)入门概述
随机推荐
滴滴开源DELTA:AI开发者可轻松训练自然语言模型
Kotlin process control and circulation
NFT: how to make money with unique assets?
Introduction to the principle of DNS
Didi open source Delta: AI developers can easily train natural language models
【云原生】Nacos-TaskManager 任务管理的使用
JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
Taobao flag insertion remarks | logistics delivery interface
Preliminary exploration of basic knowledge of MySQL
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
[Nacos cloud native] the first step of reading the source code is to start Nacos locally
2021-12-21 transaction record
Wechat enterprise payment to change access, open quickly
HiEngine:可媲美本地的云原生内存数据库引擎
RHCSA2
C alarm design
深度长文探讨Join运算的简化和提速
How to connect the API interface of Taobao open platform (super detailed)
超高效!Swagger-Yapi的秘密
View and terminate the executing thread in MySQL