dimanche 19 février 2017

Or in If statements [duplicate]

This question already has an answer here:

I'm trying to figure out why multi "or" statements in this block are not being utilized. I'm fresh to this so forgive my ignorance. The first block runs as intended, but the second block will begin the loop again with any input. I imagine I could get it to work using "and" and "==" to spell it out individually, but is there not a faster way to phrase it?Any tips would be awesome!

import random

print "Here we go!"

while True:
  print (random.randint(1,6))
  again = raw_input("Do you want to roll again?")
  if again != "y":
    print "Goodbye!"
    break


import random

print "Here we go!"

while True:
  print (random.randint(1,6))
  again = raw_input("Do you want to roll again?")
  if again != "y" or "Y" or "Yes" or "yes":
    print "Goodbye!"
    break

Thanks again!

Aucun commentaire:

Enregistrer un commentaire