龙空技术网

畅享聊:Python的练习题(5)

LearningYard学苑 146

前言:

目前我们对“python个位数为5”大约比较关注,兄弟们都想要剖析一些“python个位数为5”的相关资讯。那么小编在网摘上网罗了一些关于“python个位数为5””的相关知识,希望看官们能喜欢,大家快快来了解一下吧!

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。今天小编为你带来

畅享聊:python的练习题(5)

欢迎您的访问!

Share interests, spread happiness, increase knowledge, and leave beautiful!

Dear you, this is LearningYard Academy.

Today, the editor brings you

Enjoy chatting: Exercises on python (5)

welcome your visit!

题目:判断101-200之间有多少个素数,并输出所有素数。

程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。    

程序源代码:

Question: Determine how many prime numbers are between 101-200 and output all prime numbers.

Program analysis: the method to determine prime number: use a number to divide 2 to sqrt (this number). If it can be divided by an integer, it indicates that this number is not prime, and vice versa.

Program source code:

输出结果如下:

The output results are as follows:

方法二:

Method 2:

方法三:

Method 3:

最后的输出结果都是一样的。

The final output is the same.

题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。

程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。

程序源代码:

Title: Print out all the "narcissus number". The so-called "narcissus number" refers to a three-digit number, and the sum of the cube of each number is equal to the number itself. For example, 153 is a "narcissus number", because 153=the third power of 1+the third power of 5+the third power of 3.

Program analysis: use the for loop to control 100-999 numbers. Each number is decomposed into one, ten, and hundreds.

Program source code:

输出结果如下:

The output results are as follows:

将三位数看成由三个数组成,并判断其各位数字立方和是否等于该数本身

Think of a three-digit number as composed of three numbers, and judge whether the sum of the cubes of its numbers is equal to the number itself

结果如下:

The results are as follows:

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!

That's it for today's sharing.

If you have a unique idea about today’s

article,

Welcome to leave us a message,

Let us meet tomorrow,

I wish you a happy day today!

本文由learningyard新学苑原创,如有侵权,请联系我们。

参考资料:菜鸟教程

翻译来源:百度翻译

文字&排版|calm

审核|闫庆红

标签: #python个位数为5