|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def dec(shu):
- while int(shu)==False :
- shu = input('请输入正确的数字:')
- shu = int(shu)
- a = shu
- if shu == 1:
- print('1=1')
- if shu == 2:
- print('2 = 1 * 2')
- if shu>2:
- print('%d = ' % shu,end='')
- while True:
- for i in range(2,shu+1):
- if shu%i==0:
- if i==shu:
- print('%d' % i,end='')
- else :
- print('%d*' % i,end='')
- shu = shu/i
- break
- if i==a:
- print('*1')
- if i==shu:
- break
复制代码
我输入的是素数的话就没错,但是输入不是素数就会报错比如下面的
>>> dec(6)
6 = 2*Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
dec(6)
File "E:\PY文件\求一个属的分解因数.py", line 13, in dec
for i in range(2,shu+1):
TypeError: 'float' object cannot be interpreted as an integer
但是这个哪来的float啊我都不知道,我看了其他人答案,像我这样写的很多啊,没搞懂我哪错了 |
|