Python 2.7 缩进错误 [英] Python 2.7 Indentation error
本文介绍了Python 2.7 缩进错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Python 新手,在以下代码中出现缩进错误:
Hi I am new to Python having an indentation error in the following code:
print "------------------------- Basics Arithamatic Calculator-------------------------"
int_num_one=input('Enter First Num: ')
int_num_two=input('Enter Second Num: ')
list_options={"+", "-", "/", "*"}
print "Which operation you want to perform *, -, +, / ?"
char_selected_option=raw_input()
print "Operation selected is %r" % (char_selected_option)
for char_symbol in list_options:
print "Char symbol is %r" % (char_symbol)
bool_operation_Not_Found=True
if char_symbol==char_selected_option:
int_result=str(int_num_one) + char_selected_option + str(int_num_two)
print int_result
print "%d %s %d = %d" % (int_num_one, char_selected_option, int_num_two, eval(int_result))
bool_operation_Not_Found=False
break
if bool_operation_Not_Found:
print "Invalid Input"
推荐答案
看起来 for 循环内部"的代码没有正确缩进,这应该可以工作.
It looks like the code 'inside' the for loop was not indented correctly, this should work.
for char_symbol in list_options:
print "Char symbol is %r" % (char_symbol)
bool_operation_Not_Found=True
if char_symbol==char_selected_option:
int_result=str(int_num_one) + char_selected_option + str(int_num_two)
print int_result
print "%d %s %d = %d" % (int_num_one, char_selected_option, int_num_two, eval(int_result))
bool_operation_Not_Found=False
break
if bool_operation_Not_Found:
print "Invalid Input"
这篇关于Python 2.7 缩进错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文