0

我有没有正确缩进的代码

if age > 18: 
if salary > 100000: 
print('success') 
elif salary < 50000: 
print('fail') 
else: 
print('get_more_info')
else: 
print('fail')

我需要得到

if age > 18: 
    if salary > 100000: 
        print('success') 
    elif salary < 50000: 
        print('fail') 
    else: 
        print('get_more_info')
else: 
    print('fail')

我尝试使用

exec(autopep8.fix_code(str))

但我得到一个错误

File "<string>", line 3
print('success') elif salary < 50000: print('fail') else: print('get_more_info') else: print('fail')
                    ^
SyntaxError: invalid syntax

我也尝试使用reindent.py 但它返回

  File "code_file.py", line 1
if age > 18: if salary > 100000: print('success') elif salary < 50000:     print('fail') else: print('get_more_info') else: print('fail')
                                                                                                      ^
SyntaxError: invalid syntax

我怎样才能解决这个问题并自动完成?

4

0 回答 0