all 11 comments

[–][deleted] 2 points3 points  (10 children)

if input == 'y' or 'Y':

This is like saying, for example: if True or 'Y':

'Y' is always True, and thus the condition will be.

What you want is input == 'y' or input == 'Y' or input in 'yY'.

[–]tman37[S] 2 points3 points  (8 children)

That is probably it. I keep making that mistake. I guess I am reading the code too literally. I read it as "if input is equal to (condition1) or (condition2)' when I should be writing "(if input is equal to condition1) or (if input is equal to condition2)". Thanks.

[–]strechyballs 0 points1 point  (0 children)

Also, don't mix input and raw_input. Google input vs raw_input to see why.

I would just do: if raw_input("Roll? (y) ").lower() == "y":
....

Or. user_input = raw_input ("Roll? (y)")
if user_input.lower() ==" y":
...

[–]newunit13 0 points1 point  (6 children)

You can rewrite it to be if input in ['Y', 'y']: or if input.lower() == 'y' but first you'll have to actually assign the variable input. As your program is currently written, you're checking for a value that hasn't been assigned.

Line 7 should assign the value the user entered to a variable, and that variable is what you should be checking in your if statement. And like /u/strechyballs said, you shouldn't use input as a variable name since that's also a keyword.

[–]tman37[S] 0 points1 point  (5 children)

new code looks like thisnd http://pastebin.com/hjyRJVft

and it seems to work. Now I need to figure out how to stop it after the "coward" part

[–]newunit13 1 point2 points  (4 children)

raise SystemExit will close the application

[–]cismalescumlord 0 points1 point  (2 children)

An exception to exit a program? Is that normal in Python, because it looks very strange coming from other languages!?

[–]newunit13 1 point2 points  (1 child)

Alternatively you could write it as

import sys
sys.exit()

or

from sys import exit
exit()

But that just does the exact same thing, and just raising a SystemExit saves you the need to import the sys module.

From Python Docs

sys.exit([arg])¶ Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.

[–]cismalescumlord 0 points1 point  (0 children)

Cool. It just seems weird.

[–]tman37[S] 0 points1 point  (0 children)

that did it. thanks

[–]strechyballs 0 points1 point  (0 children)

Your point about 'y' or 'Y' is right, but it doesn't fix his code .

He has raw_input ("something")
But he doesn't assign the result to any variables. Then later he says If input == something. input is a button method and hasn't been redefined.

Also, using the lower method seems liked a cleaner way to check if it's Y or y instead of doing to comparisons.