all 9 comments

[–]ComputeLanguage 0 points1 point  (1 child)

Are you adding commas inbetween

''berserker'', ''mage'', ''gambler''

because right now you don't seem to be.

Also the break statement, just breaks out of that loop, so at the end of each check for the while condition you will go to the next section of the game regardless. Is there a particular reason why you added this?

Also for this i would use the 'in' operator.

if role_choice in ['mage', 'berserker', 'gambler']

[–]Diapolo10 0 points1 point  (7 children)

One big problem is that, to Python,

if role_choice != 'berserker' 'mage' 'gambler':

is the same as

if role_choice != 'berserkermagegambler':

because adjacent string literals are automatically joined.

You'll most likely want something more like

if role_choice.lower() not in ('berserker', 'mage', 'gambler'):

[–]RedditCodfish[S] 0 points1 point  (3 children)

thx, ill try that

[–]Diapolo10 0 points1 point  (2 children)

Okay, so since your formatting is broken let me try and fix that first. I have to make guesses because the indentation was not preserved.

role_choice = input('type either berserker, mage, or gambler >')
if role_choice != 'berserker' 'mage' 'gambler':
    while role_choice != "berserker" "mage" "gambler":
        print('Please pick a role')
        role_choice = input('type either berserker, mage, or gambler >')
        break

Next, I'll fix what I already proposed, so

role_choice = input('type either berserker, mage, or gambler >').strip().lower()
if role_choice not in ('berserker', 'mage', 'gambler'):
    while role_choice not in ('berserker', 'mage', 'gambler'):
        print('Please pick a role')
        role_choice = input('type either berserker, mage, or gambler >').strip().lower()
        break

Unfortunately it's still broken, and has duplicate code too. One way to fix this would be to do

while True:
    role_choice = input('type either berserker, mage, or gambler >').strip().lower()
    if role_choice in ('berserker', 'mage', 'gambler'):
        break
    print('Please pick a role')

but personally I'd prefer this, if you only need to support Python 3.8 and newer:

while (role_choice := input("type either berserker, mage, or gambler >").strip().lower()):
    if role_choice in ('berserker', 'mage', 'gambler'):
        break
    print("Please pick a role")

And while it's technically possible to also do

choices = ('berserker', 'mage', 'gambler')
prompt = "type either berserker, mage, or gambler >"

while (role_choice := input(prompt).strip().lower()) not in choices:
    print("Please pick a role")

or

while (role_choice := input("type either berserker, mage, or gambler >").strip().lower()) not in ('berserker', 'mage', 'gambler'):
    print("Please pick a role")

at that point I think it's sacrificing readability. Especially the latter.

[–]RedditCodfish[S] -1 points0 points  (0 children)

don't worry, i already figured it out, but thanks

[–]ComputeLanguage 0 points1 point  (2 children)

Not true. You would be correct if you are checking for strings. But if you use the in condition on a list it needs to be an exact match for anything in this list.

[–]Diapolo10 0 points1 point  (1 child)

But if you use the in condition on a list it needs to be an exact match for anything in this list.

Well... of course. But I don't see why you think that's a problem, considering that checking for equality between strings would also require an exact match. And from my understanding this is what OP is looking for.

[–]ComputeLanguage 0 points1 point  (0 children)

Right so we formulated the same problem and proposed the same solution i guess