2016-07-26 78 views
0

之前仔细阅读我的问题我想说,感谢大家至少会尽力帮助ME的Python - 聊斋志异“意外缩进”错误

嘿,伙计们!几个星期前,我决定学习Python 2中的脚本。我使用learnpythonthehardway书。现在我试着做小游戏,但是当我启动我的游戏时,它输入了非常奇怪的“意外缩进”错误。我相信,有什么不对我的脚本...这就是:

import random 

打印 “Airchiet sirtule:” 打印 “Sheudzlebeli [1250]”

sirtule的raw_input =( “<” )

ELIF sirtule == “Sheudzlebeli”: rand4 = random.randint(1250)

print "Gamoicanit chafiqrebuli ricxvi [1,250]" 
print "Sirtule - Sheudzlebeli." 
print "Mcdelobebis raodenoba - 7" 

tryh1 = raw_input("< ") 
    if (int(tryh1) > int(rand4)): 
     print "Mititebuli ricxvi metia chafiqrebulze." 
    elif (int(tryh1) < int(rand4)): 
     print "Mititebuli ricxvi naklebia chafiqrebulze." 
    elif (int(tryh1) == int(rand4)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 

tryh2 = raw_input("< ") 
    if (int(tryh2) > int(rand4)): 
     print "Mititebuli ricxvi metia chafiqrebulze." 
    elif (int(tryh2) < int(rand4)): 
     print "Mititebuli ricxvi naklebia chafiqrebulze." 
    elif (int(tryh2) == int(rand4)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh3 = raw_input("< ") 
    if (int(tryh3) > int(rand4)): 
     print "Mititebuli ricxvi metia chafiqrebulze." 
    elif (int(tryh3) < int(rand4)): 
     print "Mititebuli ricxvi naklebia chafiqrebulze." 
    elif (int(tryh3) == int(rand4)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh4 = raw_input("< ") 
    if (int(tryh4) > int(rand4)): 
     print "Mititebuli ricxvi metia chafiqrebulze." 
    elif (int(tryh4) < int(rand4)): 
     print "Mititebuli ricxvi naklebia chafiqrebulze." 
    elif (int(tryh4) == int(rand4)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh5 = raw_input("< ") 
    if (int(tryh5) > int(rand4)): 
     print "Mititebuli ricxvi metia chafiqrebulze." 
    elif (int(tryh5) < int(rand4)): 
     print "Mititebuli ricxvi naklebia chafiqrebulze." 
    elif (int(tryh5) == int(rand4)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh6 = raw_input("< ") 
    if (int(tryh6) > int(rand4)): 
     print "Mititebuli ricxvi metia chafiqrebulze." 
    elif (int(tryh6) > int(rand4)): 
     print "Mititebuli ricxvi naklebia chafiqrebulze." 
    elif (int(tryh6) == int(rand4)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh7 = raw_input("< ") 
    if (int(tryh7) != int(rand4)): 
     print "Samwuxarod tqven waaget." 
     print "Chafiqrebuli ricxvi iyo -", rand4, 
    elif (int(tryh7) == int(rand)): 
     print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 

错误,我得到:“文件“G c.py”,管线234 如果(ITN(tryh1)> INT(rand4)): IndentationError:意想不到缩进“

欲还说SORRY。我对这个非常愚蠢的问题感到厌烦,原因在于我是新手在脚本中。

+0

取消缩进你'if's和'elif's让他们在同一水平上面摆着线,即'tryh1的raw_input =(“<”)',和unindent这些代码块内的相同数量 – jonhopkins

回答

0

在Python中,缩进很重要,这个错误是说你的缩进有些问题。在这种情况下,if语句不需要缩进。所以,正确的代码将

print "Gamoicanit chafiqrebuli ricxvi [1,250]" 
print "Sirtule - Sheudzlebeli." 
print "Mcdelobebis raodenoba - 7" 

tryh1 = raw_input("< ") 
if (int(tryh1) > int(rand4)): 
    print "Mititebuli ricxvi metia chafiqrebulze." 
elif (int(tryh1) < int(rand4)): 
    print "Mititebuli ricxvi naklebia chafiqrebulze." 
elif (int(tryh1) == int(rand4)): 
    print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 

tryh2 = raw_input("< ") 
if (int(tryh2) > int(rand4)): 
    print "Mititebuli ricxvi metia chafiqrebulze." 
elif (int(tryh2) < int(rand4)): 
    print "Mititebuli ricxvi naklebia chafiqrebulze." 
elif (int(tryh2) == int(rand4)): 
    print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh3 = raw_input("< ") 
if (int(tryh3) > int(rand4)): 
    print "Mititebuli ricxvi metia chafiqrebulze." 
elif (int(tryh3) < int(rand4)): 
    print "Mititebuli ricxvi naklebia chafiqrebulze." 
elif (int(tryh3) == int(rand4)): 
    print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh4 = raw_input("< ") 
if (int(tryh4) > int(rand4)): 
    print "Mititebuli ricxvi metia chafiqrebulze." 
elif (int(tryh4) < int(rand4)): 
    print "Mititebuli ricxvi naklebia chafiqrebulze." 
elif (int(tryh4) == int(rand4)): 
    print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
tryh5 = raw_input("< ") 
if (int(tryh5) > int(rand4)): 
    print "Mititebuli ricxvi metia chafiqrebulze." 
elif (int(tryh5) < int(rand4)): 
    print "Mititebuli ricxvi naklebia chafiqrebulze." 
elif (int(tryh5) == int(rand4)): 
    print "Gilocavt tqven gamoicanit chafiqrebuli ricxvi." 
+0

你的意思是我需要设置所有“如果”“Elif”和“tryh”在同一水平? –

+0

我不是Python的专家,但他的代码工作,所以我猜是的 –

+0

非常感谢你的队友:) –