+ 9
Using function with input again but with my defined input
So am building a code on python that i defined a function that takes user input , but now i want to use the same function only with my defined input what is the best way to do that
11 odpowiedzi
+ 6
you mean make a new version with no input in it
+ 6
isn't there anyway to use the same one I forget to mention that I am using another function that takes the function we are talking about as an argument only I need it with my own string.
+ 6
command = input().split()
def get_noun (noun):
noun = command [2]
if noun in GameObject.objects :
return noun
else :
choose a .....
def get_char(verb) :
char = command [0]
#.... the same as noun
def get_verb (noun):
verb_word = command [1
if .....]
def get_input ():
get_char(get_verb(get_noun(noun)))
def hit(noun)
........
def enemy_hit()
+ 6
what am trying to do is get the enemy to hit back using the same effects of hit
+ 6
I tried don't know why posting a code is causing an error in connection though everything else doesn't have the error don't know if its an app bug , but i'll
keep u posted when it does work ,thanks for the help anyway
+ 6
it worked check it out
https://code.sololearn.com/coV719RKG12t/?ref=app
+ 6
am trying to get the enemy to hit back after input the :enemy_hit function is what am trying to define without having to write all the hit() code again
p.s. I know its still too WET am just a beginner my purpose from this code is only learning
+ 1
you could define your function with a "text" parameter (or whatever you want) and have a version that asks for user input before calling the function with your input as an argument.
+ 1
Sorry, your code is complicated, I have a hard time understanding it... (simple is better than complex / complex is better than complicated)
0
give some code, I'm not sure to understand what you mean
0
Sorry, I still don't understand. And your indentation doesn't help. Maybe you could post some code in the Playground?