Skip to content

Instantly share code, notes, and snippets.

@ysmood
Created October 27, 2013 04:59
Show Gist options
  • Select an option

  • Save ysmood/7178133 to your computer and use it in GitHub Desktop.

Select an option

Save ysmood/7178133 to your computer and use it in GitHub Desktop.
low = 0
high = 100
guess_number = (low + high) / 2
print("Please think of a number between 0 and 100!")
while True:
char = raw_input("Is your secret number " +
str(guess_number) + "?\n" +
"Enter 'h' to indicate the guess is too high." +
"Enter 'l' to indicate the guess is too low." +
"Enter 'c' to indicate I guessed correctly .")
if not char:
break
elif char == 'c':
break
elif char == 'h':
high = guess_number
elif char == 'l':
low = guess_number
else:
print("Sorry, I did not understand your input.")
guess_number = (low + high) / 2
print("Game over. Your secret number was: " + str(guess_number))
@acgtyrant

Copy link
Copy Markdown

這個語法錯誤我知道怎麼避免,但我只關心為什麼一個賦值表達式並不能像 C 那樣直接嵌入 while 判斷式裡面...

話說是什麼語言可以直接從 raw_input 看出來的吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment