0

我有一个要求看电影的小应用程序。当评分超过 50 时,返回观看。如果没有,请选择另一部电影。虽然当我到达movieDec中的条件时,它不会回到函数的顶部来计算电影的分数。想不通这个

def getScore():
   choose = raw_input("pick a movie ")
   rt = RT()
   info = rt.search(choose)
   rating1 = info[0].get('ratings').get('critics_score')
   rating2 = info[0].get('ratings').get('audience_score')
   stars = (rating1 + rating2) / 2
   return rating1, rating2, stars


def movieDec():
   critic, aud, stars = getScore()
   print 'Critics gave it a %s' %critic
   print 'Audiences gave it a %s' %aud
   print 'The average rating is %s' %stars
   while stars < 50:
       print "That's no good, pick again"
       getScore()
    print 'Good choice.'
4

3 回答 3

2

您没有更新stars循环中的变量。尝试:

while stars < 50:
   print "That's no good, pick again"
   critic, aud, stars = getScore()
于 2013-02-16T14:22:26.840 回答
0

在您的循环中,您忽略了的返回值getScore()

   getScore()

将其更改为:

   critic, aud, stars = getScore()
于 2013-02-16T14:21:49.017 回答
0

上面这个更正的代码将第二次调用 getScore() 函数(如果星数 <50),但在循环如下所示之前它不会显示分数:

while stars < 50:
   print "That's no good, pick again"
   critic, aud, stars = getScore()
   print 'Critics gave it a %s' %critic
   print 'Audiences gave it a %s' %aud
   print 'The average rating is %s' %stars
于 2013-02-16T14:31:51.890 回答