-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomated Dictionary Python program examples.py
More file actions
152 lines (105 loc) · 5.61 KB
/
Automated Dictionary Python program examples.py
File metadata and controls
152 lines (105 loc) · 5.61 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Automated Dictionary Python program examples:
# Created by Joseph C. Richardson, GitHub.com
# Let's use the Python Idle that will help us create a dictionary for us.
# You must type four dictionary keys and values to create your dictionary.
# Execute/run the Python program example below to view your created
# dictionary, along with its variable name. Simply highlight all the blue text
# output, and then copy then paste that blue Python Idle text output back
# into your Python Idle editor. Next, execute/run the pasted Python code
# and watch it create a dictionary, as if you had created the actual Python
# dictionary and layout yourself.
user_input_data_dictionary = { }
keys = user_input_data_dictionary.keys()
values = user_input_data_dictionary.values()
keys_values = 0
print('''
Let me help you create a dictionary with Python. Please
type each data dictionary key and value, one at a time,
followed by the "Enter" key:''')
while keys_values < 4:
user_input_key = input(f'\nPlease type dictionary key{keys_values+1}: ').strip()
user_input_value = input(f'Please type dictionary value{keys_values+1}: ').strip()
user_input_data_dictionary.update({user_input_key:user_input_value})
keys_values += 1
print(f'\nuser_input_data_dictionary = {user_input_data_dictionary}')
print(f'\nHere are your {keys} and {values}:')
print(f'\nYou have {len(keys)} keys and {len(values)} values:')
print(f"\n{user_input_data_dictionary.get('place key here')}")
print(f"\n{user_input_data_dictionary.get('place key here','Key not found:')}") # optional
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a dictionary for us.
# You must type a number of dictionary keys and values to create your
# dictionary. Execute/run the Python program example below to view
# your created dictionary, along with its variable name. Simply highlight
# all the blue text output, and then copy then paste that blue Python Idle
# text output back into your Python Idle editor. Next, execute/run the
# pasted Python code and watch it create a dictionary, as if you had
# created the actual Python dictionary and layout yourself.
user_input_data_dictionary = { }
keys = user_input_data_dictionary.keys()
values = user_input_data_dictionary.values()
keys_values = 0
print('''
Let me help you create a dictionary with Python. Please
type each data dictionary key and value, one at a time,
followed by the "Enter" key:''')
while True:
try:
user_input_dectionary_length = int(input(
'\nHow many keys and values would you like to create?: ').strip())
except ValueError:
print('\nNumbers only please: ')
continue
break
while keys_values < user_input_dectionary_length:
user_input_key = input(f'\nPlease type dictionary key{keys_values+1}: ').strip()
user_input_value = input(f'Please type dictionary value{keys_values+1}: ').strip()
user_input_data_dictionary.update({user_input_key:user_input_value})
keys_values += 1
print(f'\nuser_input_data_dictionary = {user_input_data_dictionary}')
print(f'\nHere are your {keys} and {values}:')
print(f'\nYou have {len(keys)} keys and {len(values)} values:')
print(f"\n{user_input_data_dictionary.get('place key here')}")
print(f"\n{user_input_data_dictionary.get('place key here','Key not found:')}") # optional
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a dictionary for us.
# You must type a number of dictionary keys and values to create your
# dictionary. Execute/run the Python program example below to view
# your created dictionary, along with its variable name. Simply highlight
# all the blue text output, and then copy then paste that blue Python Idle
# text output back into your Python Idle editor. Next, execute/run the
# pasted Python code and watch it create a dictionary, as if you had
# created the actual Python dictionary and layout yourself.
user_input_data_dictionary = { }
keys = user_input_data_dictionary.keys()
values = user_input_data_dictionary.values()
keys_values = 0
print('''
Let me help you create a dictionary with Python. Please
type each data dictionary key and value, one at a time,
followed by the "Enter" key:''')
while True:
try:
user_input_dectionary_length = int(input(
'\nHow many keys and values would you like to create?: ').strip())
if user_input_dectionary_length < 2:
print(f'\nYour dictionary must be at least two keys and two values long.')
continue
else:
break
except ValueError:
print('\nNumbers only please: ')
continue
break
while keys_values < user_input_dectionary_length:
user_input_key = input(f'\nPlease type dictionary key{keys_values+1}: ').strip()
user_input_value = input(f'Please type dictionary value{keys_values+1}: ').strip()
user_input_data_dictionary.update({user_input_key:user_input_value})
keys_values += 1
print(f'\nuser_input_data_dictionary = {user_input_data_dictionary}')
print(f'\nHere are your {keys} and {values}:')
print(f'\nYou have {len(keys)} keys and {len(values)} values:')
print(f"\n{user_input_data_dictionary.get('place key here')}")
print(f"\n{user_input_data_dictionary.get('place key here','Key not found:')}") # optional
# I am almost a complete Walking Human Computer Science Research
# Laboratory Machine on Two Legs... 😁