어떤 이유로이 코드가 작동하지 않습니까? 나는 return 1을 시도해 봤지만 어떤 이유로 오류가 발생했다. 숫자가 너무 길지만 이상적인 방법이 없다면 코드가 처음으로 돌아가고 싶다.Python 코드가 예상대로 작동하지 않습니다.
# Find the cube root of a perfect cube
x = int(input('Enter an integer: '))
if x > 5000:
break:
print('too long')
### this code is broken ^^^^^
ans = 0
while ans**3 < x:
ans = ans + 1
if ans**3 != x:
print(str(x) + ' is not a perfect cube')
else:
print('Cube root of ' + str(x) + ' is ' + str(ans))
IndentationError: unexpected indent
>>> runfile('/home/dux/pyyyyy.py', wdir=r'/home/dux')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/dux/pyyyyy.py", line 7
print('wrong'):
^
SyntaxError: invalid syntax
>>> runfile('/home/dux/pyyyyy.py', wdir=r'/home/dux')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/dux/pyyyyy.py", line 7
break:
^
SyntaxError: invalid syntax
>>> runfile('/home/dux/pyyyyy.py', wdir=r'/home/dux')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/dux/pyyyyy.py", line 8
print('wrong')
^
IndentationError: unexpected indent
>>> runfile('/home/dux/pyyyyy.py', wdir=r'/home/dux')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/dux/pyyyyy.py", line 7
break:
^
SyntaxError: invalid syntax
>>>
[무엇이'중단 '입니까?] (http://docs.python.org/2/tutorial/controlflow.html)? – goncalopp
중단 점이나 'yield'에'break'를 혼동하고 있습니까? – ereOn