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

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

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

今天小编为你带来

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

欢迎您的访问!


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

Dear you, this is LearningYard Academy.

Today, the editor brings you

Enjoy chatting: Python Exercises (3)

welcome your visit!






大家好,今天小编继续带着大家看看Python的经典练习题。

Hello, everyone. Today, I will continue to show you the classic exercises of Python.


题目:输入三个整数x,y,z,请把这三个数由小到大输出。

程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。

Topic: Input three integers x, y, z, and output the three numbers from small to large.

Program analysis: we try to put the minimum number on x, first compare x with y, if x>y, exchange the values of x and y, then compare x with z, if x>z, exchange the values of x and z, so that x can be minimized.


程序源代码:

program source code:


结果如下:

The results are as follows:


这里提供第二种方法,代码如下:

The second method is provided here. The code is as follows:

结果如下:

The results are as follows:

题目:斐波那契数列。

程序分析:斐波那契数列,也称兔子数列,是指1,1,2,3,5,8,13,21,34,55,89,144......这样一个数列,在这个数列当中,从第三项起,每一项都是前两项数字之和。

在数学上,费波那契数列是以递归的方法来定义:


Topic: Fibonacci series.

Program analysis: Fibonacci sequence, also known as rabbit sequence, refers to a sequence of 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89144... In this sequence, each item is the sum of the first two numbers from the third item.

Mathematically, Fibonacci sequence is defined by recursion:

代码及结果如下:

The codes and 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新学苑原创,如有侵权,请联系我们。

参考资料:Python菜鸟教程

翻译来源:百度翻译

文字&排版 calm

审核 闫庆红

展开阅读全文

页面更新:2024-03-12

标签:练习题   递归   菜鸟   数列   之和   最小   题目   代码   程序   快乐

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top