当前位置:网站首页>[weekly pit] calculate the sum of primes within 100 + [answer] output triangle
[weekly pit] calculate the sum of primes within 100 + [answer] output triangle
2022-07-06 20:23:00 【Crossin's programming classroom】
Zero basis python Introductory tutorial :python666.cn
Hello everyone , Welcome to Crossin Programming classroom of !
Today's topic is very short :
Calculation 1 To 100 The sum of all prime numbers within
The so-called prime number , Except 1 And the number itself , A number that is not divided by other natural numbers .
To judge whether a number is a prime number , This is not difficult
find 1~100 Within the scope of , All prime numbers , This is very simple
Add up the found prime numbers , This is even less difficult
Top up 3 Step together OK La !
But if you are interested , You can further consider the algorithm complexity of your method , See whose method is simpler .
in addition , For this question , I have an interesting solution , Not exactly according to the above idea , To be announced next week .( I don't know if anyone's answer will be the same as I think )
Detailed answers and reference codes will be given in the next column , You can also refer to the code in the message of other students .
I look forward to your answers , I hope you can complete the whole series .
Simple code can be submitted directly in the message , Long code is recommended paste.ubuntu.com or
codeshare.io And other code sharing sites , Just copy the code and save it , You can get a share address , Very convenient .
For past questions, click the collection at the beginning of the article “ Every Monday ” Enter the view .
【 answer 】 Output triangle
The key to this problem is to calculate well The number of spaces in each line And The current number of lines Correspondence of .
Output multiple spaces , You can go through the loop , It can also be directly passed through “ String multiplication ” Realization , namely :
' Original string ' * nYou can get n individual ' Original string ' New string composed of .
Refer to the answer :( come from @KE10)
def ntriangle(n):
print('*'*n)
n -= 1
while n > 1:
print('*'+' '*(n-2)+'*')
n -= 1
print('*')
ntriangle(5)_ Previous articles are recommended _
If you need to know Paid premium courses And Teaching Q & a service
Please be there. Crossin Programming classroom of Internal reply : 666

边栏推荐
- 微信小程序常用集合
- 【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
- 腾讯云数据库公有云市场稳居TOP 2!
- Tencent T3 teaches you hand in hand. It's really delicious
- Maximum likelihood estimation and cross entropy loss
- Notes on beagleboneblack
- Event center parameter transfer, peer component value transfer method, brother component value transfer
- [network planning] Chapter 3 data link layer (3) channel division medium access control
- mod_ WSGI + pymssql path SQL server seat
- 使用ssh连接被拒
猜你喜欢
![[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100

Enumeration gets values based on parameters

【每周一坑】信息加密 +【解答】正整数分解质因数

【GET-4】

报错分析~csdn反弹shell报错

"Penalty kick" games

New generation garbage collector ZGC

5. Wireless in vivo nano network: top ten "feasible?" problem

RT thread I2C tutorial

Case ① | host security construction: best practice of 3 levels and 11 capabilities
随机推荐
Poj3617 best cow line
Wechat applet common collection
Rhcsa Road
Synchronization of data create trigger synchronization table for each site
“罚点球”小游戏
Cesium 点击绘制圆形(动态绘制圆形)
Tencent T3 Daniel will teach you hand-in-hand, the internal information of the factory
5. Nano - Net in wireless body: Top 10 "is it possible?" Questions
Tencent architects first, 2022 Android interview written examination summary
How to handle the timeout of golang
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
Gui Gui programming (XIII) - event handling
Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
【计网】第三章 数据链路层(3)信道划分介质访问控制
Basic knowledge of lists
报错分析~csdn反弹shell报错
[cloud native and 5g] micro services support 5g core network
【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
BUUCTF---Reverse---easyre
Extraction rules and test objectives of performance test points