错误"不匹配的输入"期待DEDENT

pan*_*ami 6 python

在本教程之后,我得到以下错误,其中y = 1; 我正在使用Netbeans 6.5 for Python.谢谢

      y=1
      ^
Run Code Online (Sandbox Code Playgroud)

SyntaxError:第8行:3不匹配的输入''期待DEDENT(temperatureconverter.py,第8行)

以下是python代码,格式化我感谢.

__author__="n"
__date__ ="$Jan 9, 2011 3:03:39 AM$"

def temp():
  print "Welcome to the NetBeans Temperature Converter."  
   y=1
   n=0
   z=input("Press 1 to convert Fahrenheit to Celsius, 2 to convert Celsius to Fahrenheit, or 3 to quit:")
    if z!=1 and z!=2 and z!=3:
        e=input("Invalid input, try again?(y or n)")
        if e==1:
            t=''
            temp()
        if e==0:
            t="Thank you for using the NetBeans Temperature Converter."
  print "Celsius Fahrenheit"  # This is the table header.
  for celsius in range(0,101,10):  # Range of temperatures from 0-101 in increments of 10
    fahrenheit = (9.0/5.0) * celsius +32 # The conversion
    print celsius, "       ", fahrenheit  # a table row
temp()
Run Code Online (Sandbox Code Playgroud)

Amn*_*non 12

print声明中,您使用了2个空格来缩进行,而在下一个声明中,您放置了3个空格.

Whitespace在Python中很重要.具体来说,如果您在一行中有一定级别的缩进,则不能仅使用另一行作为下一行.

  • @Tim:我相信OP使用了不同的Python实现.也许是Jython? (3认同)