[英]can't figure out the error with the following code
我是 python 的新手,并试图找出以下代码中的错误
x = int(input("input x"))
y = int(input("input y"))
if x>y :
x -= y
elif y>x:
x += y
else if x==y :
print("y = ", y)
print("x= ", x)
如果代码没有正确缩进,Python 会抛出编译错误, else if
在 Python 中无效,则语法为elif
。
错误:
File "test.py", line 15
x -= y
^
IndentationError: expected an indented block
File "test.py", line 15
x += y
^
IndentationError: expected an indented block
File "test.py", line 18
else if x==y :
^
SyntaxError: invalid syntax
固定代码:
x = int(input("input x"))
y = int(input("input y"))
if x>y :
x -= y
elif y>x:
x += y
elif x==y :
print("y = ", y)
print("x = ", x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.