0

The program should keep asking the user to enter title and review while the answer for "Do you want to continue(Y/N)?" is Y. Instead it ask the user only once. Can someone help me figure out while the loop does not continue . Thanks!

#!/usr/bin/env python

def main():

 listOfReviews = obtainListOfReviews()
 displayResults(listOfReviews)

def obtainListOfReviews():
 listOfReviews = []
 carryOn ='Y'
 while carryOn =='Y':
  title = raw_input("Enter title:")
  review = int(input("Enter review:"))

  st = MovieReview(title, review)
  listOfReviews.append(st)
  carryOn = raw_input("Do you want to continue?(Y/N)? ")
  carryOn = carryOn.upper()
  return listOfReviews

def displayResults(listOfReviews):
     for r in listOfReviews:
         print(r)

class MovieReview:
 def __init__(self, title = " ", review = 0):
  self._title = title
  self._review = review
 def setTitle(self, title):
  self._title = title
 def setReview(self, review):
  self._review = review
 def getTitle(self):
  return self._title
 def getReview(self):
  return self._review
 def __str__(self):
  return ("Title: " + str(self._title) + " \nreview: " + str(self._review))
main()
4
  • Because you have return in the while loop Commented Apr 25, 2016 at 14:18
  • Your return is part of the while loop. Unindent it. Commented Apr 25, 2016 at 14:19
  • return listOfReviews causes the function obtainListOfReviews() to return the values stored in listOfReviews to be assigned to the variable listOfReviews in main(). Commented Apr 25, 2016 at 14:20
  • If you used a decent indentation level, instead of a single space, the issue might be more obvious. Commented Apr 25, 2016 at 14:34

1 Answer 1

0

You have a wrong indentation for you line "return listOfReviews" :

def obtainListOfReviews():
 listOfReviews = []
 carryOn ='Y'
 while carryOn =='Y':
  title = raw_input("Enter title:")
  review = int(input("Enter review:"))

  st = MovieReview(title, review)
  listOfReviews.append(st)
  carryOn = raw_input("Do you want to continue?(Y/N)? ")
  carryOn = carryOn.upper()

 # Correct indentation
 return listOfReviews
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.