当前位置:网站首页>实现 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)
边栏推荐
- 奔跑,开路
- Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
- Wechat enterprise payment to change access, open quickly
- Distributed solution - completely solve website cross domain requests
- 单独编译内核模块
- Using docker for MySQL 8.0 master-slave configuration
- Full text search of MySQL
- SAP SEGW 事物码里的 ABAP 类型和 EDM 类型映射的一个具体例子
- JDBC -- use JDBC connection to operate MySQL database
- 由扫地增而引起的小叙
猜你喜欢

Pinduoduo flag insertion remarks API

Taobao flag insertion remarks | logistics delivery interface

Distributed cache architecture - cache avalanche & penetration & hit rate

Setting up sqli lab environment

Annotation problem and hidden Markov model

RHCSA7

前几年外包干了四年,秋招感觉人生就这样了..

Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
![[Nacos cloud native] the first step of reading the source code is to start Nacos locally](/img/f8/d9b848593cf7380a6c99ee0a8158f8.png)
[Nacos cloud native] the first step of reading the source code is to start Nacos locally

Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification
随机推荐
A possible investment strategy and a possible fuzzy fast stock valuation method
关于 SAP UI5 getSAPLogonLanguage is not a function 的错误消息以及 API 版本的讨论
CVPR 2022 | single step 3D target recognizer based on sparse transformer
Four common problems of e-commerce sellers' refund and cash return, with solutions
Transactions on December 23, 2021
Kotlin variable
关于 SAP UI5 floating footer 显示与否的单步调试以及使用 SAP UI5 的收益
Iterator details in list... Interview pits
自然语言处理系列(一)入门概述
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
2021-12-21 transaction record
单独编译内核模块
RHCSA7
10 minute fitness method reading notes (5/5)
2021-12-22 transaction record
#yyds干货盘点#js截取文件后缀名
10 minute fitness method reading notes (2/5)
jxl笔记
Comprehensive upgrade of Taobao short video photosynthetic platform
RHCSA1