A community for students.
Here's the question you clicked on:
 0 viewing
 2 years ago
I just did Exercise 1.7 (in http://ocw.mit.edu/courses/electricalengineeringandcomputerscience/6189agentleintroductiontoprogrammingusingpythonjanuaryiap2011/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
 2 years ago
I just did Exercise 1.7 (in http://ocw.mit.edu/courses/electricalengineeringandcomputerscience/6189agentleintroductiontoprogrammingusingpythonjanuaryiap2011/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

This Question is Closed

Daeruin
 2 years ago
Best ResponseYou've already chosen the best response.1If 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.

Daeruin
 2 years ago
Best ResponseYou've already chosen the best response.1I should add that sometimes your last elif can be replaced with else, since at that point you've exhausted all the possibilitiesassuming you have controlled the input, which it looks like you have.

rsmith6559
 2 years ago
Best ResponseYou've already chosen the best response.0Users have an amazing ability to screw up. Having that extra else gives your program a fighting chance. IMO, do it.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.