2016-07-26 45 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

非常感謝你的隊友:) –