python-crash-course/Chapter_06/6-04_glossary2.py
2025-01-26 20:35:06 -05:00

34 lines
1.2 KiB
Python

# Exercise 6-4 Glossary 2
# Learning Objective: Loop through dictionary.
words = {
'loop': 'A repetetive process of actions.',
'operator': 'A symbol of an action to take place.',
'if statement': 'A conditional process.',
'variable': 'An object that can change its value.',
'constant': 'An object whose value does not change.',
#added 5 more definitions:
'dictionary': 'An container of key-value pairs.',
'set': 'A list of keys or value that are unique and contain no duplicates.',
'output': 'The result of a command or action.',
'keys': 'An element of a dictionary with an associated value.',
'value': 'An element of a dictionart linked to its key.',
}
for word, definition in words.items():
print(f"\n{word.title()} is defined as:\n{definition}")
# old code from 6-03_glossary.py
'''
print(f"Loop:\n{words['loop']}\n--------------------------------------------")
print(f"\nOperator:\n{words['operator']}\n--------------------------------------------")
print(f"\nif Statement:\n{words['if statement']}\n--------------------------------------------")
print(f"\nVariable:\n{words['variable']}\n--------------------------------------------")
print(f"\nConstant:\n{words['constant']}\n--------------------------------------------")
'''