PLEASE EXPLAIN THIS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

PLEASE EXPLAIN THIS

I havent understood what this whole code does/means. Can someone explain? 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()

24th Jun 2020, 1:34 PM
Feba Maryann
Feba Maryann - avatar
1 Answer
+ 1
If you enter say as input it will call the 2nd function Wich prints out 'you said x' while x is either 'nothing' or a second word you entered. If you don't enter say first it will output unknown verb because only say is in your dictionary. "say hello" will output you said hello whilest "hello" will output unknown verb? edit: for sololearn playground I recommend: #while true: at the bottom cause the loop won't work here
24th Jun 2020, 2:03 PM
loeckchen[INACTIVE]