python 5的倍数_查找所有低于1000的数字的和,这是Python中3或5的倍数
python 5的倍數(shù)
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.
有時(shí),我們需要找到可以被3和5整除的所有整數(shù)或數(shù)字的總和,直到數(shù)千,因?yàn)閿?shù)千是一個(gè)太大的數(shù)字,這就是為什么我們很難做到這一點(diǎn)。 因此,在這里,我們將使用Python編程語言來完成此任務(wù),并在幾秒鐘內(nèi)解決問題。 為了解決這個(gè)問題,我們將使用范圍函數(shù)。 因此,在找到總和之前,我們將學(xué)習(xí)一些有關(guān)范圍函數(shù)的知識(shí)。
What is the range function in Python?
Python中的范圍函數(shù)是什么?
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中可用的內(nèi)置函數(shù)。 簡(jiǎn)而言之,該范圍允許它們?cè)诮o定間隔內(nèi)生成一系列數(shù)字。 此函數(shù)僅適用于整數(shù),即整數(shù)。
Syntax of range() function:
range()函數(shù)的語法:
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.
它需要三個(gè)參數(shù)來開始 , 停止和步進(jìn) ,并且取決于用戶選擇如何生成數(shù)字序列? 默認(rèn)情況下, range()函數(shù)采用步驟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的倍數(shù)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的python 5的倍数_查找所有低于1000的数字的和,这是Python中3或5的倍数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java RandomAccessFil
- 下一篇: websocket python爬虫_p