Not really a question but are you wondering about the verb/say function name bit? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Not really a question but are you wondering about the verb/say function name bit?

Yeah, me too. I think it's definitely calling say(noun) and not verb(noun) def get_input(): command = input(": ").split() verb_word = command[0] if verb_word in verb_dict: verb = verb_dict[verb_word] else: print("Unknown verb {}". format(verb_word)) return if len(command) >= 2: noun_word = command[1] print (verb(noun_word)) else: print(verb("nothing")) def say(noun): return 'You said "{}"'.format(noun) verb_dict = { "say": say, } while True: get_input()

5th Jul 2019, 2:23 PM
khusboo Agarwal
khusboo Agarwal - avatar
2 Answers
+ 3
Oh Yeah! Thanks!
5th Jul 2019, 3:43 PM
khusboo Agarwal
khusboo Agarwal - avatar
+ 1
def get_input(): command = input("Enter ").split() # input is split up into two words and assigned into command verb_word = command[0] # the first word in [command] is assigned to verb_word if verb_word in verb_dict: # check if the first word inputted is in the dictionary verb_dict verb = verb_dict[verb_word] # when true the corresponding value of the dictonary is assigned to the variable verb else: print("Unknown verb {}".format(verb_word)) # when false this line is printed return if len(command) >= 2: # check if the length of the input is larger or equal to two characters noun_word = command[1] # when true the second inputted word is assigned to the variable noun_word print(verb(noun_word)) # when true ( verb == say) the function say is called with the passed argument noun_word else: print(verb("nothing")) # when false "nothing" is printed out , when the second word is missing def say(noun): return 'You said "{}"'.format(noun) verb_dict = {"say": say,} while True: get_input()
26th Mar 2020, 1:26 PM
Arun Tomy
Arun Tomy - avatar