我正在尝试运行此代码,但是遇到了错误,并花了所有时间进行调试。寻求帮助
n = int(input())
if n % 2 == 1:
print("Weird")
elif(n%2==0) and 2<=n<=5:
print("Not Weird")
elif(n%2==0) and 6<=n<=20:
print("Weird")
else:
print(" Not Weird")
答案 0 :(得分:3)
if/elif/else
语句必须全部使用相同的缩进级别。
if x:
# do stuff
elif y:
# do other stuff
elif z:
# do more stuff
else:
# do something else
答案 1 :(得分:0)
您不应缩进elif等。它们应该像缩进一样。另外,您无需将条件语句括在括号中。这有效:
n = int(input())
if n%2 == 1:
print("Weird")
elif n%2 == 0:
print("Not Weird")
elif n%2 == 0 and 6 <= n <= 20:
print("Weird")
else:
print(" Not Weird")