不应出现python标识错误
我试图解决这个问题很多次,但我不能解决我尝试了一切,但每次都显示错误消息 错误消息是 第15行第2个副本的文件计算 中断 ^ 缩进错误:未缩进与任何外部缩进级别不匹配 我不知道如何解决这个问题,我想我已经把它完美地缩进了四个空格不应出现python标识错误,python,python-3.x,Python,Python 3.x,我试图解决这个问题很多次,但我不能解决我尝试了一切,但每次都显示错误消息 错误消息是 第15行第2个副本的文件计算 中断 ^ 缩进错误:未缩进与任何外部缩进级别不匹配 我不知道如何解决这个问题,我想我已经把它完美地缩进了四个空格 我找不到任何错误。您可能希望在菜单选项的除法之后添加一个换行符,否则它就太完美了 如果我混淆了制表符和空格,这种情况有时会发生在崇高的文本中。我是专门为崇高的文本回答的,因为这就是你在评论中所说的 在升华文本中,当您突出显示空白时,您实际上可以看到它是选项卡还是空格,
我找不到任何错误。您可能希望在菜单选项的除法之后添加一个换行符,否则它就太完美了 如果我混淆了制表符和空格,这种情况有时会发生在崇高的文本中。我是专门为崇高的文本回答的,因为这就是你在评论中所说的 在升华文本中,当您突出显示空白时,您实际上可以看到它是选项卡还是空格,如下所示: 注意左边的两个箭头。看到点的地方有空格,看到线的地方有标签 为了使间距一致,我建议您手动返回并删除代码,然后手动并一致地重新缩进代码,或者使用一根短绒重新缩进。升华文本为该视图提供了一些工具->缩进->*和
升华文本中另一个有用的技巧是在文件中搜索制表符,并将其替换为空格。对不起,我无法复制您的问题。请检查前面的行。确保您只使用空格或制表符。请确认您没有混合制表符和空格。您正在从addition=a+b开始的每一行上混合制表符和空格。我相信很多环境都可以向您展示这一点,但我使用的是记事本++,它有一个视图->显示符号->显示空白和制表符选项。@AustinA打印函数中的语法错误是什么,看起来像标准的f字符串语法Py3.6。重新启动内核有时会有所帮助。我知道这是显而易见的,也是站不住脚的,但也许吧!那么,为什么它显示了机器中的错误?我使用的是命令提示符,您使用的是什么版本?Python 2或3?我正在使用Jupyter笔记本。我可以尝试使用命令提示符。让我再打给你。@MaxvonHippel:我需要50个代表才能做到这一点!:这成功了!!所以现在我使用缩进作为空格,还是应该使用缩进作为制表符?是否使用制表符或空格的问题是个人风格之一。这也是我们的话题。做你认为更酷的事:
a=int(input('enter the first number')) #we ask for input
b=int(input('enter the second number'))
while True:
choice=int(input('enter the number corresponding to the operation you want to \nperform \n1)addition \n2)subtraction \n3)multiplication \n4)division '))
#we ask for the user choice
if choice==1: #if the user opts for addition
addition=a+b
print(f'the addition of the 2 numbers is {addition} ') #ans
ans=input('want to try another operation? yes or no')
if ans=='yes': #if the user whishes to use another operation
continue
else: #if the user opts out
print('thank you for using')
break
elif choice==2:
subtraction=a-b #same for others but diffrent opperation
print(f'the subtraction of the 2 numbers is {subtraction} ')
ans=input('want to try another operation? yes or no')
if ans=='yes':
continue
else:
print('thank you for using')
break
elif choice==3:
multiplication=a*b
print(f'the multiplication of the 2 numbers is {multiplication} ')
ans=input('want to try another operation? yes or no')
if ans=='yes':
continue
else:
print('thank you for using')
break
else:
division=a//b
remainder=a%b
print(f'the division of the 2 numbers is {division} \nand the remainder is{remainder} ')
ans=input('want to try another operation? yes or no')
if ans=='yes':
continue
else:
print('thank you for using')
break