代码报错
print("Give me two numbers,and I'll divide them")print("Enter 'q' to quit")
while True:
first_number = input("First number:")
if first_number == 'q':
break
second_number = (input('Second number:')
try:
answer = int(first_number) / int(second_number)
except ZeroDivisionError:
print("You can't divide by 0")
else:
print(answer)
求教为什么这串代码不断显示语法错误 else语句你多打了一个缩进 还是不行啊? 并且报错的位置一直在try语句这里 second_number = (input('Second number:')
你少一个括号 second_number = (input('Second number:')
这里你少一个括号,同时if 与else之间内容的缩进方式也不对 第八行有一个括号不搭配second_number = (input('Second number:')
楼主试一下下面的代码,然后和你自己的代码比一下
print("Give me two numbers,and I'll divide them")
print("Enter 'q' to quit")
while True:
first_number = raw_input("First number:")
if first_number == 'q':
break
second_number = raw_input("Second number:")
try:
answer = int(first_number) / int(second_number)
except ZeroDivisionError:
print("You can't divide by 0")
else:
print("answer = %d\n" % answer) 少了括号,还有缩进的问题 统一回复,感谢楼上的大神 路过 都是人才,我有问题也可以求助吗 second_number后差一个括号;
else:后面的缩进多一个!
页:
[1]