![](/img/trans.png)
[英]Pycharm TabError: inconsistent use of tabs and spaces in indentation
[英]TabError: inconsistent use of tabs and spaces in indentation | Coding a simple calculator
我正在尝试编写一个简单的计算器。
以下是更新后的代码。 但还是同样的错误。
running = True
while running:
print("1 Addition \
2 Subtraction \
3 Multiplication \
4 Division \
5 remainder \
6 Power of \
7 Quit")
O = int(input('What Operaton you want to do ? '))
F = float(input('Enter first number: '))
S = float(input('Enter Second number: '))
if O == 1:
R = F + S
print(F,'+',S,'=',R)
elif O == 2:
R = F - S
print(F,'-',S,'=',R)
elif O == 3:
R = F * S
print(F,'*',S,'=',R)
elif O == 4:
R = F / S
print(F,'/',S,'=',R)
elif O == 5:
R = F % S
print(F,'%',S,'=',R)
elif O == 6:
R = F ** S
print(F,'**',S,'=',R)
else:
print('Quit')
running = False
在运行时,我面临以下错误。
$/usr/local/bin/python3.7 file1.py 文件“file1.py”,第 20 行 R = F - S ^ TabError:在缩进中使用不一致的制表符和空格
您不必要地缩进了while
语句。
running = True
while running:
应该:
running = True
while running:
不过还有一个问题:
代替:
else O == 7:
print('Quit')
running = False
你应该写:
else:
print('Quit')
running = False
else
不接受任何论点。 当没有if
或elif
条件为真时选择的语句集很简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.