Computer Science, asked by PrasannaGopiRam, 5 months ago

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 jai696
47

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

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

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by allysia
49

I did it in python:

Here you go,

\\\tt import \  keyword \\\tt keywords= keyword.kwlist \\\tt user\_terms= ["break" , "case", "cont inue", "d e f a u l t", "else", "de f", \\\tt "go to", "if", "return"] \\\tt for \ word \ in \ user\_terms:\\{\qquad if \ word \ in\ keywords: }\\\tt{\qquad {\qquad print( " word,"is \ a \ keyword . ")}}}\\\tt {\qquad else: }\\\tt{\qquad {\qquad print( " word,"is\ not \ a \ keyword . ")}}\\

Similar questions