我在 python 中创建了一个字典作为我的第一个“主要”项目。我正在使用它来跟踪关键词。输入的只是示例,因此请随时改进我的定义(:
我是 python 新手,所以请随时批评我的技术,这样我就可以在它变得更糟之前学习!
我想知道的是,是否有一种方法可以处理字典中未包含的搜索。
如“抱歉,找不到您要查找的单词,您要尝试其他搜索吗?”
无论如何,这是我的代码:
Running = True
Guide = {
'PRINT': 'The function of the keyword print is to: Display the text / value of an object',
'MODULO': 'The function of Modulo is to divide by the given number and present the remainder.'
'\n The Modulo function uses the % symbol',
'DICTIONARY': 'The function of a Dictionary is to store a Key and its value'
'\n separated by a colon, within the {} brackets.'
'\n each item must be separated with a comma',
'FOR LOOP': 'The For Loop uses the format: \n '
'For (variable) in (list_name): (Do this)',
'LINE BREAKS': ' \ n ',
'LOWERCASE': 'To put a string in lower case, use the keyword lower()',
'UPPERCASE': 'To put a string in upper case use the keyword upper()',
'ADD TO A LIST': 'To add items to a list, use the keyword: .append'
'\n in the format: list_name.append(item)',
'LENGTH': 'To get the length of a STRING, or list use the keyword len() in the format: len(string name)', }
while Running:
Lookup = raw_input('What would you like to look up? Enter here: ')
Lookup = Lookup.upper()
print Guide[str(Lookup)]
again = raw_input('Would you like to make another search? ')
again = again.upper()
if again != ('YES' or 'Y'):
Running = False
else:
Running = True