ZKX's LAB

python输出水仙花数 用python写水仙花数,四个数用end',`输出,该怎么在保留其他逗号的情况下,去掉最后一个逗号

2021-04-25知识4

Python输出水仙花数 import mathfor i in range(100,1000):tmp1=math.pow(int(str(i)[0]),3)tmp2=math.pow(int(str(i)[1]),3)tmp3=math.pow(int(str(i)[2]),3)if i=tmp1+tmp2+tmp3:print i

用python写水仙花数,四个数用end',`输出,该怎么在保留其他逗号的情况下,去掉最后一个逗号 那得看你怎么写的代码了。已经print出去了,是没法去掉了,想法子第四个不是end=','就是了。比如:水仙花数flt=lambda x:x=int(x/100)*3+int(x%100/10)*3+(x%10)*3print(','.join(str(_)for_in filter(flt,range(100,1000))))

Python算水仙花数的程序怎么改进? 水仙花数是一个N位非负整数,其各个位数字的N次方和等于该数本身。下面是我的代码:def sxh():for a…

随机阅读

qrcode
访问手机版