在阅读我的问题之前,我想向所有人致力于帮助我的人
嘿伙计们!几周前,我决定学习Python 2中的脚本。我使用了Learnpythonthehardway book。现在我尝试制作小游戏,但是当我启动游戏时,它输入了非常奇怪的“意外缩进”错误。我确信我的剧本没有任何问题......这里是:import random
打印“Airchiet sirtule:” 打印“Sheudzlebeli [1,250]”
sirtule = raw_input(“<”)
elif sirtule ==“Sheudzlebeli”: rand4 = random.randint(1,250)
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."
我得到错误:“文件'gc.py',第234行 if(itn(tryh1)&gt; int(rand4)): IndentationError:意外缩进“
我也想说抱歉。我很抱歉这个非常愚蠢的问题,原因是我在写作时是新手。
答案 0 :(得分: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."