0

This code perfectly works if the player inputs a valid / defined input on the first try. If the input is not correct (For example "theif" or "Warrior") the function will be called again. However that second (or third,...) time will always return null although that 2nd time the input was correct.

(This is just a part of the program)

def classDecider():
    print("Available Classes: Swordsman, Magician, Thief")
    enteredClass = input("Enter Class: ")
    if enteredClass == "Swordsman":
        return "Swordsman"
    elif enteredClass == "Magician":
        return "Magician"
    elif enteredClass == "Thief":
        return "Thief"
    else:
        classDecider()        

def CharacterCreation():
    nameOfPlayer = input("Enter your name: ")
    chosenClass = classDecider()
    print(chosenClass)
    players.append(player(nameOfPlayer, chosenClass))
    chosenCharacter +=1
CharacterCreation()
Apollox
  • 25
  • 6

3 Answers3

0

You have forgotten about return in else clause, replace

def classDecider():
    print("Available Classes: Swordsman, Magician, Thief")
    enteredClass = input("Enter Class: ")
    if enteredClass == "Swordsman":
        return "Swordsman"
    elif enteredClass == "Magician":
        return "Magician"
    elif enteredClass == "Thief":
        return "Thief"
    else:
        classDecider()

using

def classDecider():
    print("Available Classes: Swordsman, Magician, Thief")
    enteredClass = input("Enter Class: ")
    if enteredClass == "Swordsman":
        return "Swordsman"
    elif enteredClass == "Magician":
        return "Magician"
    elif enteredClass == "Thief":
        return "Thief"
    else:
        return classDecider()
Daweo
  • 31,313
  • 3
  • 12
  • 25
-1

Just add return

....
else:
     return classDecider() 
....
AmrAnwar
  • 59
  • 1
  • 8
-1

Change your classDecider() in else into return classDecider(). You have to return the final result

Nicolas
  • 51
  • 12