Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I always get the final print, even writing the class that I want. How do I fix this?

So, I’m trying to create a RPG just for fun. But, while creating the classes, I noticed that I couldn’t choose my class. Everytime I choose a class, I always get the final print. How do I fix this?

while (True):
    print("Select your class\n")
    print("\nKnight\nArcher\nTank\nRogue\n\n")

    classe = input("")

    if((classe.strip()).lower() == "Knight"):
        forca = 10
        defe = 4
        hp = 8
        agi = 2
        inte = 2
        break

    elif((classe.lower()) == "Archer"):
        forca = 6
        defe = 6
        hp = 6
        inte = 8
        agi = 7
        break

    elif((classe.strip()).lower() == "Tank"):
        forca = 5
        defe = 8
        hp = 10
        inte = 3
        break

    elif((class.strip()).lower() == "Rogue"):
        strenght += 6
        def = 5
        hp = 5
        inte = 6
        agi = 10
        break
    else:
        print("You need to choose one.")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are using .lower() then comparing it to words with capital letters (Tank). So it will never match. Try this:

while (True):
    print("Select your class\n")
    print("\nKnight\nArcher\nTank\nRogue\n\n")

    classe = input("")

    if((classe.strip()).lower() == "knight"):
        forca = 10
        defe = 4
        hp = 8
        agi = 2
        inte = 2
        break

    elif((classe.lower()) == "archer"):
        forca = 6
        defe = 6
        hp = 6
        inte = 8
        agi = 7
        break

    elif((classe.strip()).lower() == "tank"):
        forca = 5
        defe = 8
        hp = 10
        inte = 3
        break

    # class is a keyword, use classe
    elif((classe.strip()).lower() == "rogue"):
        # Does this need to be an equals?
        strenght = 6
        # Def is a keyword, use defe
        defe = 5
        hp = 5
        inte = 6
        agi = 10
        break
    else:
        print("You need to choose one.")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading