randint()问题与Python数字猜谜游戏

时间:2017-05-22 15:49:23

标签: python random

以下是一段代码,可以让游戏更低。它应该在两个变量之间得到一个随机数。但它并不介于两个变量之间。试试吧,你会看到。

var item = this.CreateTreeNode("dashboard", id, queryStrings, "Dashboard", "icon-dashboard", true);

item.RoutePath = "/ReportingSection/framed/%2Fumbraco%2Fbackoffice%2FMySection%2FReportingSection";

nodes.Add(item);

1 个答案:

答案 0 :(得分:2)

你想改变“低”而不是“guess_num”,if else语句中的“max”也是如此...

  

guess_num = low应为low = guess_num

也不要str()guess_num

from random import randint
high = 1000
low = 1
guess_num = 5
def me_guess(guess_num,high,low):
  print " "
  guess_num = randint(low,high)

  fact = raw_input(str(guess_num) + " (higher or lower or yes) ")
  if fact == "higher":
    low = guess_num
    me_guess(guess_num,high,low)
  elif fact == "lower":
    high = guess_num
    me_guess(guess_num,high,low)
  elif fact == "yes":
    print "Yay! I got it."
    me_finish(guess_num)
  else:
    print "Error. Guessing again."
    me_guess(guess_num,high,low)

me_guess(guess_num,high,low)