![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
文章平均质量分 75
Neil-
吾日三省吾身~
展开
-
斐波那契数列
#! /usr/bin/python3# -*- coding:utf-8 -*-def fibonacci(): '''输出斐波那契数列 ''' n = int(input('请输入需要输出的项数:')) x = 0 y = 1 for _ in range(n): print(y) x, y = y, x+yfibonacci()运行结果...原创 2019-05-07 19:39:16 · 99 阅读 · 0 评论 -
百钱白鸡问题
#! /usr/bin/python3# -*- coding: utf-8 -*-def buy_chicken(): '''鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何? Args: Returns: 鸡翁、鸡母、鸡雏个数 ''' results = [] for i in range(0, 20): res ...原创 2019-05-07 19:52:44 · 327 阅读 · 0 评论 -
完全数(完美数)
#! /usr/bin/python3# -*- coding: utf-8 -*-import mathdef perfect_num(): '''如果一个数恰好等于它的真因子之和,则称该数为“完全数”,又称“完美数”。所谓的真因子是指除了其本身外的所有因子(约数) ''' num = int(input('Please input a positive integer:...原创 2019-05-07 19:59:17 · 6225 阅读 · 0 评论 -
水仙花数
#! /usr/bin/python3# -*- coding: utf-8 -*-def narcissistic_num(): ''' 水仙花数:一个三位数,各位数的三次幂之和等于该数字本身大小 ''' num = int(input('请输入一个正整数:')) if type(num) != type(3): print('输入的不是正整数!') ret...原创 2019-05-07 20:01:37 · 123 阅读 · 0 评论 -
两个数的最大公约数与最小公倍数
最大公约数:GCD,greatest common divisor最小公倍数:LCM,least common multiple#! /usr/bin/python3# -*- coding: utf-8 -*-def get_GCD_LCM(): '''get the greatest common divisor and the least common multiple ...原创 2019-05-07 20:05:03 · 752 阅读 · 1 评论 -
回文数判断
#! /usr/bin/python3# -*- coding: utf-8 -*-import mathdef palindrome(): num = int(input('请输入一个正整数:')) while num < 0 or type(num) != type(1): num = int(input('请重新输入一个正整数:')) s = str(nu...原创 2019-05-07 22:51:07 · 246 阅读 · 0 评论