Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

I just did Exercise 1.7 (in http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/assignments/MIT6_189IAP11_hw1.pdf ) which is a Rock, Paper, Scissors game. My question is, when you have a series of if/elif conditionals, is it good practice to have an extra else at the end to catch any unexpected conditions? Or is that unnecessary or confusing? You can see my code at https://gist.github.com/3781336

MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
If you guarantee that only allowed answers are given, then account for each of those answers, there should be no need for the extra else at the end. Having said that, I did added it anyway, just in case. As long as the if/elif conditions account for all possibilities, you should be good.
I should add that sometimes your last elif can be replaced with else, since at that point you've exhausted all the possibilities--assuming you have controlled the input, which it looks like you have.
Users have an amazing ability to screw up. Having that extra else gives your program a fighting chance. IMO, do it.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question