Search code examples
pythonundefineduser-defined-functions

How do i execute a def function in python?


Im writing a simple choice game in python and im pretty new i just learned how to make a def function but when i run it nothing is working and if i remove the def main() command theres an error that pops up that says game() can be undefined. Someone knows how to clear that? Thanks.strong text Thats the code i did (sorry its in french but the code it self is in english) All my syntaxe is good i only get this one error.

import random

def main():
print("Le labyrinthe éternel par Benjamin Robert")
print("=========================================")
print("Veuillez écrire la lettre choisi lorsque vous voillez ceci /n ")
game()


def game():
print("Bonjours nouveau combatant.")
player_name = input("Ainsi j'aimerais savoir quel est votre nom? ")
print("Bonjour " + player_name + "!")
yer_points()

def yer_points():
player_points = (input("Voulez vous savoir quel sont vos force et faiblesse a aléatoire? Oui?/n o ou Non?/n n "))

 if player_points == "o ":
    print("Allons-y ")
    player_resistance()
else:
    print("Faux choix dommage! ")
    player_resistance()

def player_resistance():
resistance = random.randrange(0, 26)
print("Votre résistance est de: " + str(resistance))
if resistance > 20:
    print("Bravo vous êtes très Résistant!")
    player_dexterite()
elif resistance > 15:
    print("Vous êtes plutôt résistant.")
    player_dexterite()
elif resistance > 10:
    print("Ça pourrais être mieux.")
    player_dexterite()
elif resistance > 5:
    print("Dommage meilleure chance la prochaine fois...")
    player_dexterite()
elif resistance < 5:
    print("Bonne chance vous aller en avoir besoin!")
    player_dexterite()


def player_dexterite():
dexterite = random.randrange(0, 26)
print("Votre dextérité est de: " + str(dexterite))
if dexterite > 20:
    print("Bravo vous êtes très vif!")
    player_luck()
elif dexterite > 15:
    print("Vous êtes plutôt vif.")
    player_luck()
elif dexterite > 10:
    print("Ça pourrais être mieux.")
    player_luck()
elif dexterite > 5:
    print("Dommage meilleure chance la prochaine fois...")
    player_luck()
elif dexterite < 5:
    print("Bonne chance vous aller en avoir besoin!")
    player_luck()

def player_luck():
chance = random.randrange(0, 26)
print("Votre chance est de: " + str(chance))
if chance > 20:
    print("Bravo vous êtes très chanceux!")
elif chance > 15:
    print("Vous êtes plutôt chanceux.")
elif chance > 10:
    print("Ça pourrais être mieux.")
elif chance > 5:
    print("Dommage meilleure chance la prochaine fois...")
elif chance < 5:
    print("Bonne chance vous aller en avoir besoin et c'est le cas de le dire!")

Solution

  • Make a function by using def function_name(). Execute it with function_name().