SyntaxError和" if未定义"

时间:2014-11-28 07:40:13

标签: python python-2.7

我不知道自己做错了什么。该计划正在显示:"syntax error""if is not defined"

task = input (' select task 1, 2 or  3. Type  5 to exit\n')


If (task == 1 ) : 
    print "I am task 1! \n"
    print "I can tell you the sum of two numbers. \n"
    n = input ('input the first number \n')
    m = input ('input the second number \n')
    sum = n + m 
    print " their sum is : ", sum, ".\n"

1 个答案:

答案 0 :(得分:2)

因为If(task == 1):

你必须写"如果"不是"如果"。大写字母"如果"必须小写

task = input (' select task 1, 2 or  3. Type  5 to exit\n')


if task == 1: 
    print "I am task 1! \n"
    print "I can tell you the sum of two numbers. \n"
    n = input ('input the first number \n')
    m = input ('input the second number \n')
    sum = n + m 
    print " their sum is : ", sum, ".\n"

这将有效。