简体   繁体   English

如何在 python 中执行 def function?

[英]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.我在 python 中编写了一个简单的选择游戏,我很新,我刚刚学会了如何制作一个 def function 但是当我运行它时,没有任何工作,如果我删除 def main() 命令,就会弹出一个错误,上面写着 game()可以是未定义的。 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. Thanks.strong 文本这就是我所做的代码(对不起,它是法语,但它自己是英语的代码)我所有的语法都很好,我只得到这个错误。

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!")

you need to call your main() in order for your script to work.您需要调用main()才能使脚本正常工作。 Just add只需添加

main()

at the very end of the file.在文件的最后。


French法语

vous devez appeler votre main() pour que votre script fonctionne. vous devez appeler votre main() pour que votre script fonctionne。 Ajoutez simplement Ajoutez 简单

main()

à la toute fin du fichier. à la toute fin du fichier。

Make a function by using def function_name() .使用def function_name()制作 function 。 Execute it with function_name() .使用function_name()执行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM