-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_lower_name.py
36 lines (24 loc) · 956 Bytes
/
match_lower_name.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# coding: utf-8
# # Practice Question Scripting
# In[1]:
## function that creates a flower_dictionary from filename
def create_flowerdict(filename):
flower_dict = {}
with open(filename) as f:
for line in f:
letter = line.split(": ")[0].lower()
flower = line.split(": ")[1].strip()
flower_dict[letter] = flower
return flower_dict
## Main function that prompts for user input, parses out the first letter
## includes function call for create_flowerdict to create dictionary
def main():
flower_d = create_flowerdict('flowers.txt')
full_name = input("Enter your First [space] Last name only: ")
first_name = full_name[0].lower()
first_letter = first_name[0]
## print command that prints final input with value from corresponding key in dictionary
print("Unique flower name with the first letter: {}".format(flower_d[first_letter]))
main()
# In[ ]: