I have been stuck for days on trying to get the would you like to reroll die 1-5
yes or no function working as no matter what I type in, it still proceeds to move on and if I put in all Y's, it still gives me the error message of I'm sorry. Please only enter Y or N.
I think I also need to define the die1-5 = random.randint(1,6) as well, but it doesn't give me the nameError that it's not defined. If there's anything I'm missing, please let me know.

- 65
- 9
-
Use parentheses to group your input checks as needed. Look up operator precedence for help; it doesn't naturally do what you expect here. Also, note that you're trying to reroll on any acceptable input, rather than paying attention to what the user gave you. – Prune Nov 27 '19 at 00:57
-
Welcome to StackOverflow. [On topic](https://stackoverflow.com/help/on-topic), [how to ask](https://stackoverflow.com/help/how-to-ask), and ... [the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) apply here. You changed your posting to invalidate the given answers; this is a violation of Stack Overflow practices. You now ask for help in fixing code you have not posted. – Prune Nov 27 '19 at 16:48
-
Welcome to StackOverflow. See [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). We cannot effectively help you until you post your MRE code and accurately specify the problem. We should be able to paste your posted code into a text file and reproduce the problem you specified. – Prune Nov 27 '19 at 16:51
2 Answers
None of your if clauses can be true -- they're all equivalent to "did the user say yes and no". I can't see a reason why the and keepDieX == 'N' or keepDieX == 'No'
clauses are in there.

- 7,555
- 8
- 46
- 88
-
what should I fix that with? I had ```elif keepDie1-5 == 'N':``` on it's own before, but it gave the same result. – Ben Nov 27 '19 at 00:53
First, get this working first for only a single roll; then expand to five dice.
if keepDie1[0] in 'Nn':
die1 = random.randint(1,6)
should handle your problem well enough; this is what a lot of programs use, only the first letter of the input. If you want a validity check, then use
if keepDie1[0] in "YyNn":
...
Also note that you converted the input to upper-case, so there's no way it can be "Yes" or "No" when you test it. See keep asking until valid for a thorough treatment of the topic.
Finally, I recommend that you check your documentation. You ask the player if she wants to re-roll each of the dice, but then store those re-roll choices as "keepDie", a name with the opposite semantics.

- 76,765
- 14
- 60
- 81
-
Since we no longer know what "it" is, we cannot help. I made the indicated changes to my copy of your code, and it works as I wrote above. I suspect that (1) you're still trying to program more than one thing you don't fully understand; (2) you have made one or more of the other logic errors included in your original code, and the combination is your problem. – Prune Nov 27 '19 at 16:55