当前位置:网站首页>实现 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)
边栏推荐
- View and modify the MySQL data storage directory under centos7
- How can non-technical departments participate in Devops?
- 10 minute fitness method reading notes (2/5)
- Compilation principle reading notes (1/12)
- OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
- 以VMware创新之道,重塑多云产品力
- Redis cluster configuration
- 上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花
- Compile kernel modules separately
- Pinduoduo flag insertion remarks API
猜你喜欢
Comprehensive upgrade of Taobao short video photosynthetic platform
Transactions on December 23, 2021
关于 SAP UI5 floating footer 显示与否的单步调试以及使用 SAP UI5 的收益
RHCSA5
石臻臻的2021总结和2022展望 | 文末彩蛋
ActiveMQ installation and deployment simple configuration (personal test)
Super efficient! The secret of swagger Yapi
stirring! 2022 open atom global open source summit registration is hot!
Shi Zhenzhen's 2021 summary and 2022 outlook | colorful eggs at the end of the article
关于 SAP UI5 getSAPLogonLanguage is not a function 的错误消息以及 API 版本的讨论
随机推荐
SAP UI5 ObjectPageLayout 控件使用方法分享
初识Linkerd项目
[Nacos cloud native] the first step of reading the source code is to start Nacos locally
研究:数据安全工具在 60% 的情况下无法抵御勒索软件
JDBC exercise - query data encapsulated into object return & simple login demo
Distributed solution - distributed session consistency problem
Comprehensive upgrade of Taobao short video photosynthetic platform
Distributed solution - distributed lock solution - redis based distributed lock implementation
Iterator details in list... Interview pits
Database connection pool & jdbctemplate
Volatile instruction rearrangement and why instruction rearrangement is prohibited
NLP engineer learning summary and index
激动人心!2022开放原子全球开源峰会报名火热开启!
HiEngine:可媲美本地的云原生内存数据库引擎
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
SAP 自开发记录用户登录日志等信息
Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
Transactions from December 27 to 28, 2021
RHCSA4