当前位置:网站首页>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)
边栏推荐
- Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
- RHCSA4
- Rocky基础知识1
- 函数的默认参数&函数参数的多种方法
- Super efficient! The secret of swagger Yapi
- Alibaba cloud SLB load balancing product basic concept and purchase process
- I met Tencent in the morning and took out 38K, which showed me the basic smallpox
- I'm doing open source in Didi
- RHCAS6
- 155. 最小栈
猜你喜欢
A specific example of ABAP type and EDM type mapping in SAP segw transaction code
Transactions from January 14 to 19, 2022
【云原生】Nacos-TaskManager 任务管理的使用
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
946. 验证栈序列
Developers, is cloud native database the future?
【Nacos云原生】阅读源码第一步,本地启动Nacos
Concurrent performance test of SAP Spartacus with JMeter
Taobao order amount check error, avoid capital loss API
Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
随机推荐
2021.12.16-2021.12.20 empty four hand transaction records
以VMware创新之道,重塑多云产品力
奔跑,开路
Transactions from January 14 to 19, 2022
stm32和电机开发(从架构图到文档编写)
国内市场上的BI软件,到底有啥区别
Rocky basics 1
What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail
Setting up sqli lab environment
Laravel document reading notes -mews/captcha use (verification code function)
Hiengine: comparable to the local cloud native memory database engine
JXL notes
A deep long article on the simplification and acceleration of join operation
SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法
关于 SAP UI5 getSAPLogonLanguage is not a function 的错误消息以及 API 版本的讨论
《2022年中國銀行業RPA供應商實力矩陣分析》研究報告正式啟動
Super efficient! The secret of swagger Yapi
Simply take stock reading notes (3/8)
leetcode:221. 最大正方形【dp状态转移的精髓】
简单上手的页面请求和解析案例