分享兴趣,传播快乐,增长见闻,留下美好! 亲爱的您,这里是LearningYard新学苑。 今天小编为你带来 畅享聊:Python的练习题(3) 欢迎您的访问! Shareinterests,spreadhappiness,increaseknowledge,andleavebeautiful! Dearyou,thisisLearningYardAcademy。 Today,theeditorbringsyou Enjoychatting:PythonExercises(3) welcomeyourvisit! 大家好,今天小编继续带着大家看看Python的经典练习题。 Hello,everyone。Today,IwillcontinuetoshowyoutheclassicexercisesofPython。 题目:输入三个整数x,y,z,请把这三个数由小到大输出。 程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果xy则将x与y的值进行交换,然后再用x与z进行比较,如果xz则将x与z的值进行交换,这样能使x最小。 Topic:Inputthreeintegersx,y,z,andoutputthethreenumbersfromsmalltolarge。 Programanalysis:wetrytoputtheminimumnumberonx,firstcomparexwithy,ifxy,exchangethevaluesofxandy,thencomparexwithz,ifxz,exchangethevaluesofxandz,sothatxcanbeminimized。 程序源代码: programsourcecode: 结果如下: Theresultsareasfollows: 这里提供第二种方法,代码如下: Thesecondmethodisprovidedhere。Thecodeisasfollows: 结果如下: Theresultsareasfollows: 题目:斐波那契数列。 程序分析:斐波那契数列,也称兔子数列,是指1,1,2,3,5,8,13,21,34,55,89,144。。。。。。这样一个数列,在这个数列当中,从第三项起,每一项都是前两项数字之和。 在数学上,费波那契数列是以递归的方法来定义: Topic:Fibonacciseries。 Programanalysis:Fibonaccisequence,alsoknownasrabbitsequence,referstoasequenceof1,1,2,3,5,8,13,21,34,55,89144。。。Inthissequence,eachitemisthesumofthefirsttwonumbersfromthethirditem。 Mathematically,Fibonaccisequenceisdefinedbyrecursion: 代码及结果如下: Thecodesandresultsareasfollows: 今天的分享就到这里了。 如果您对今天的文章有独特的想法, 欢迎给我们留言, 让我们相约明天, 祝您今天过得开心快乐! Thatsitfortodayssharing。 Ifyouhaveauniqueideaabouttoday’sarticle, Welcometoleaveusamessage, Letusmeettomorrow, Iwishyouahappydaytoday! 本文由learningyard新学苑原创,如有侵权,请联系我们。 参考资料:Python菜鸟教程 翻译来源:百度翻译 文字排版calm 审核闫庆红