Created
May 18, 2019 10:32
-
-
Save LanHao0/5a02a7e8ca9a51191fb3be205e1ac1c6 to your computer and use it in GitHub Desktop.
n位水仙花数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_n=input("input_n:") | |
new_n=int(num_n) | |
range_left="1" | |
range_right="1" | |
a=[] | |
result=[] | |
for i in range(new_n-1): | |
range_left=range_left+"0" | |
for i in range(new_n): | |
range_right=range_right+"0" | |
range_left=int(range_left) | |
range_right=int(range_right) | |
print(range_left) | |
print(range_right) | |
for ii in range(range_left,range_right): | |
final_answer=0 | |
str_i=str(ii) | |
a=list(str_i) | |
#print(a) | |
for dd in range(new_n): | |
cc=int(a[dd]) | |
final_answer=final_answer + cc**new_n | |
#print(final_answer) #打印答案 | |
if(final_answer==ii): | |
result.append(ii) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment