0

I am trying to get a loop that allows the user to pick "yes" or "no" and if not the program says invalid input and repeats. I just get invalid input every time and it won't give me a "yes" or "no"

def main():
  choice = raw_input("Would you like to open a file? (yes or no) ")
  while true:
    if choice is 'no':
      print("Goodbye")
      break
    elif choice != "yes" or choice != "no":
      print("invalid input")
      break   
    elif choice is 'yes':
      file = get_file()
      image = make_image(file)
      show_image(image)   

def get_file():
  file = pickAFile()
  return file

def make_image(file):
  image = makePicture(file)
  return image

def show_image(image):
  show(image)

main()
savannah
  • 17
  • 4
  • `if choice != "yes" or choice != "no"` is always true! Use `and` instead. Also, [`is` is for object identity; use `==` for equality instead](https://stackoverflow.com/q/2988017/1270789). – Ken Y-N Nov 16 '17 at 00:38
  • that helped a lot, thanks. But how can I make it repeat without just repeating `invalid input` over and over if I take `break` out? – savannah Nov 16 '17 at 01:06
  • I took out `break` and redefined `choice` again, nevermind – savannah Nov 16 '17 at 01:10
  • You could also use if/elif/else just remove middle test and place invalid option in else – grail Nov 16 '17 at 02:01
  • That is what I had in the first place, but I could have been doing something wrong. – savannah Nov 17 '17 at 05:47

0 Answers0