python 5的倍数_查找所有低于1000的数字的和,这是Python中3或5的倍数
python 5的倍數
Sometimes, we need to find the sum of all integers or numbers that are completely divisible by 3 and 5 up to thousands, since thousands are a too large number that’s why it becomes difficult for us. So, here we will do it in Python programming language that solves the problem in just a few seconds. To solve this problem, we will use the range function. So, before going to find the sum we will learn a little bit about range function.
有時,我們需要找到可以被3和5整除的所有整數或數字的總和,直到數千,因為數千是一個太大的數字,這就是為什么我們很難做到這一點。 因此,在這里,我們將使用Python編程語言來完成此任務,并在幾秒鐘內解決問題。 為了解決這個問題,我們將使用范圍函數。 因此,在找到總和之前,我們將學習一些有關范圍函數的知識。
What is the range function in Python?
Python中的范圍函數是什么?
The range() is a built-in function available in Python. In simple terms, the range allows them to generate a series of numbers within a given interval. This function only works with the integers i.e. whole numbers.
range()是Python中可用的內置函數。 簡而言之,該范圍允許它們在給定間隔內生成一系列數字。 此函數僅適用于整數,即整數。
Syntax of range() function:
range()函數的語法:
range(start, stop, step)It takes three arguments to start, stop, and step and it depends on users choose how they want to generate a sequence of numbers? By default range() function takes steps of 1.
它需要三個參數來開始 , 停止和步進 ,并且取決于用戶選擇如何生成數字序列? 默認情況下, range()函數采用步驟1。
Program:
程序:
# initialize the value of n n=1000 # initialize value of s is zero. s=0 # checking the number is divisible by 3 or 5 # and find their sum for k in range(1,n+1):if k%3==0 or k%5==0: #checking condition s+=k# printing the result print('The sum of the number:',s)Output
輸出量
The sum of the number: 234168翻譯自: https://www.includehelp.com/python/find-the-sum-of-all-numbers-below-1000-which-are-multiples-of-3-or-5.aspx
python 5的倍數
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python 5的倍数_查找所有低于1000的数字的和,这是Python中3或5的倍数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java RandomAccessFil
- 下一篇: 你没有见过的 7 种 for 循环优化,