Python初级算法题目有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1690个文字,预计阅读时间需要7分钟。
pythondef calculate_three_digit_angel_number(a, b, c): return a3 + b3 + c**3
示例:计算ABC的3位天使数a=1b=2c=3result=calculate_three_digit_angel_number(a, b, c)print(result)
1、3位水仙花数计算
"3位水仙花数”是指一个三位整数,其各位数字的3次方和等于该数本身。
例如:
ABC是一个“3位水仙花数”,则:A的3次方+B的3次方+C的3次方 = ABC。
使用Python,输出所有的3位水仙花数。
>>> for i in range(100,1000): if pow(i // 100 , 3) + pow(i % 10 , 3) + pow(i // 10 % 10, 3) == i: print(i,end=" ")
>>> 153 370 371 407
Process finished with exit code 0
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。与水仙花数类似
同样的,与水仙花数相似,回文数的判断方法也是采取相应的方式
2、回文数的判断
“回文”是指正读反读都能读通的句子。
本文共计1690个文字,预计阅读时间需要7分钟。
pythondef calculate_three_digit_angel_number(a, b, c): return a3 + b3 + c**3
示例:计算ABC的3位天使数a=1b=2c=3result=calculate_three_digit_angel_number(a, b, c)print(result)
1、3位水仙花数计算
"3位水仙花数”是指一个三位整数,其各位数字的3次方和等于该数本身。
例如:
ABC是一个“3位水仙花数”,则:A的3次方+B的3次方+C的3次方 = ABC。
使用Python,输出所有的3位水仙花数。
>>> for i in range(100,1000): if pow(i // 100 , 3) + pow(i % 10 , 3) + pow(i // 10 % 10, 3) == i: print(i,end=" ")
>>> 153 370 371 407
Process finished with exit code 0
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。与水仙花数类似
同样的,与水仙花数相似,回文数的判断方法也是采取相应的方式
2、回文数的判断
“回文”是指正读反读都能读通的句子。

