畅享聊:Python的;练习题(6)  第1张

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

亲爱的您,那里是LearningYard新学苑。

今天小编为你带来

畅享聊:Python的;操练题(6)

欢送您的拜候!

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

Dear YOU, this is LearningYard Academy.

Today, the editor brings you

Enjoy chatting: Python; Exercises (6)

welcome your visit!

今天,小编继续带着各人一路做做有关Python的操练题。

Today, Xiaobian continues to lead us to do exercises on Python.

标题问题:将一个正整数合成量因数。例如:输入90,打印出90=2*3*3*5。

法式阐发:对n停止合成量因数,应先找到一个最小的量数k,然后按下述步调完成:(1)若是那个量数恰等于n,则申明合成量因数的过程已经完毕,打印出即可。(2)若是n<>k,但n能被k整除,则应打印出k的值,并用n除以k的商,做为新的正整数你n,反复施行第一步。(3)若是n不克不及被k整除,则用k+1做为k的值,反复施行第一步。

法式源代码:

Title: Divide a positive integer into prime factors. For example, enter 90 and print 90=2 * 3 * 3 * 5.

Program analysis: To decompose the prime factor of n, first find a minimum prime number k, and then complete the following steps:

(1) If the prime number is exactly equal to n, it means that the process of decomposing the prime factor is over. Print it out.

(2) If n<>k, but n can be divided by k, the value of k should be printed out, and the quotient of n divided by k should be used as a new positive integer, you n, and rePEat the first step.

(3) If n cannot be divided by k, use k+1 as the value of k and repeat the first step.

Program source code:

畅享聊:Python的;练习题(6)  第2张

成果如下:

The results are as follows:

畅享聊:Python的;练习题(6)  第3张

标题问题:操纵前提运算符的嵌套来完成此题:进修成就>=90分的同窗用A暗示,60-89分之间的用B暗示,60分以下的用C暗示。

法式阐发:法式阐发:(a>b) ? a:b 那是前提运算符的根本例子。

法式源代码:

Question: Use the nesting of conditional operators to complete this question: students with grades>=90 are represented by A, students with grades between 60 and 89 are represented by B, and students with grades below 60 are represented by C.

Program analysis: program analysis: (a>b)? a: B This is a basic example of conditional operators.

Program source code:

畅享聊:Python的;练习题(6)  第4张

成果如下:

The results are as follows:

畅享聊:Python的;练习题(6)  第5张

标题问题:一个数若是刚好等于它的因子之和,那个数就称为"完数"。例如6=1+2+3.编程找出1000以内的所有完数。

法式源代码:

Title: If a number is exactly equal to the sum of its factors, the number is called "perfect". For example, 6=1+2+3. Program to find all the completions within 1000.

Program source code:

畅享聊:Python的;练习题(6)  第6张

成果如下:

The results are as follows:

畅享聊:Python的;练习题(6)  第7张

今天的分享就到那里了。

若是您对今天的文章有奇特的设法,

欢送给我们留言,

让我们相约明天,

祝您今天过得高兴快乐!

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

审核|闫庆红