One programming language has the following keywords that can not be used as identifers- break, case, continue, default, else, for, def, goto, if , return and etc. Now, write a program to check if the given word is keyword/not.
Answers
Answered by
47
def is_keyword(word):
keywords = ["break", "case", "continue", "default", "else", "for", "def", "goto", "if" , "return", "etc"]
for keyword in keywords:
if keyword == word:
return 1
return 0
print("keyword") if is_keyword((w := input("word: "))) else print("not keyword")
Answered by
49
I did it in python:
Here you go,
Similar questions