这里的目标是什么? [英] What is the intended block here?

查看:81
本文介绍了这里的目标是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的初学者。所以想知道这里的问题。



我尝试过:



  print ' 键入数字:'
number = int(输入( 输入数字 ))
如果(数字% 2 )!= 0:
return 奇怪
elif
(2< = n => 5)
print 不奇怪

elif
(6< = n => 20)
print 奇怪的

elif :
(n> 20)
print 不奇怪

解决方案

由于您发布的代码无法真正解答没有缩进,而Python需要适当的缩进。



但你的 elif 语句是错误的。它们的语法类似于 if 语句的语法(参见 4。更多控制流工具 - Python 2.7.15文档 [ ^ ]):

 如果 [表达式]:
条件为真时执行的代码在这里
elif [表达式]:
条件为真时执行的代码在这里
结束if - elif here


它应该是:

  print ' 输入一个数字:')
n = int(输入( 输入数字:))
if (n% 2 )!= 0:
print 奇怪的
elif (n> = 2 n< = 5) :
print 不奇怪
elif (n> = 6 n< = 20):
print 奇怪的
elif (n> 20):
print N ot奇怪的


参见 Python教程 - Python 3.4.9rc1文档 [ ^ ]。

I'm a beginner to python. So want to know the problem here.

What I have tried:

print('type a number:')
number=int(input("Enter a number"))
if (number % 2)!=0 :
return "Weird"
elif :
(2<=n=>5)
print("Not Weird")

elif :
(6<=n=>20)
print("Weird")

elif:
(n>20)
print("Not Weird")

解决方案

That can't be actually answered because your posted code has no indentation at all while Python requires proper indentation.

But your elif statements are wrong. Their syntax is similar to those of if statements (see 4. More Control Flow Tools — Python 2.7.15 documentation[^] ):

if [expression]:
    # code to be executed when condition is true goes here
elif [expression]:
    # code to be executed when condition is true goes here
# End of if - elif here


It should be:

print('type a number:')
n = int(input("Enter a number: "))
if (n % 2) !=0 :
  print("Weird")
elif (n>= 2 and n<=5):
  print("Not Weird")
elif (n>= 6 and n<=20):
  print("Weird")
elif (n>20):
  print("Not Weird")


See The Python Tutorial — Python 3.4.9rc1 documentation[^].


这篇关于这里的目标是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆