Created
March 19, 2019 14:47
-
-
Save davegotz/c90ad898c20f7724a14727ff71e31ecc to your computer and use it in GitHub Desktop.
Dictionary example with university colors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get university colors from the user and return as a dict | |
def get_colors(): | |
color_dict = {} | |
univ_name = input("Enter a university name (or enter to stop): ") | |
while univ_name != '': | |
univ_color = input("Enter the color: ") | |
color_dict[univ_name] = univ_color | |
# Get the next university name... | |
univ_name = input("Enter a university name (or enter to stop): ") | |
return color_dict | |
# Print the university colors | |
def print_colors(univ_colors): | |
# Loop over all keys, printing out each value. | |
for univ in univ_colors: | |
print("The color for", univ, "is", univ_colors[univ]) | |
# Main function | |
def main(): | |
color_dict = get_colors() | |
print_colors(color_dict) | |
# Run the program | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment