#!/usr/bin/env python
import easygui as eg
start = eg.msgbox('In your head, pick a number between 1 and 100. No matter what, I will guess it in no more than 7 tries. When you think of a number, press OK to start the program.')
maximum = 100
minimum = 0
middle = (maximum-minimum)/2
attempt= 1
while True:
if attempt > 7:
eg.msgbox('You cheated. Terminating...')
break
else:
yon = eg.boolbox("Is your number: " + str(middle) + '?', 'Guess Result',('Yes','No'))
if yon == 1:
eg.msgbox("Found in " + str(attempt) + " try!")
break
if yon == 0:
choice = eg.boolbox("Was my guess..." , 'High or Low?' , ('High' , 'Low')
if choice == 0:
minimum = middle
middle = int(round(float(maximum+minimum)/2))
elif choice == 1:
maximum = middle
middle = int(round(float(maximum+minimum)/2))
else:
eg.msgbox"Enter valid input!";"Lets start again from the last step"
continue
attempt+= 1
好的,我在第 20 行不断收到缩进错误。我想不通。我的语法看起来不错。我回去删除了所有缩进并重新缩进(以确保混合中没有空格)。为什么给我这个?我该如何解决?
最让我困惑的是我写了相同的代码,但没有导入 EasyGUI 模块,也没有修改 EasyGUI,但除此之外它是相同的代码。if/elif/else 在同一个位置,除了 'eg.msgbox' 省略了 'print' 命令和 raw_input's 被替换为 'boolbox' 之外,一切都相同。
编辑 - 第 20 行是:
if yon == 0:
线