-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsolutions.py
More file actions
333 lines (268 loc) · 11.8 KB
/
solutions.py
File metadata and controls
333 lines (268 loc) · 11.8 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#Comments are text that will not be executed in your code. Rather comments are for other programmers to read.
# All of the exercises below are commented out. Write your Javascript code after each exercise.
#Variables and Data Types
#Print each variable and test your code in the terminal using the Python interpreter
#example
greeting = 'Hello Prepster'
print(greeting); #this should print 'Hello Prepster'
#1 Variables with a String value
#Declare variables named first_name, last_name, birth_place, hobby, role_model, famous_quote, fav_president, fav_food, fav_color, fav_song
#Assign your own string values to each variable and print each variable.
first_name = 'Charlie'
print(first_name)
last_name = 'Brown'
print(last_name)
birth_place = 'Minnesota'
print(birth_place)
hobby = 'football'
print(hobby)
role_model = 'Snoopy'
print(role_model)
famous_quote = 'Good grief!'
print(famous_quote)
fav_president = 'Obama'
print(fav_president)
fav_food = 'carrot cake'
print(fav_food)
fav_color = 'yellow'
print(fav_color)
fav_song = "Don't Stop Believin"
print(fav_song)
#2 String Concatenation
#Declare a variable named full_name and concatenate first_name and last_name. Print the full_name variable.
full_name = first_name + " " + last_name
print(full_name)
#Declare a variable named intro that creates the following sentence:
#'Hello, my name is x and I was born in y.' Where x is full_name and y is birth_place. Print the intro variable.
intro = 'Hello, my name is '+ full_name + ' and I was born in ' + birth_place + '.'
print(intro)
#Declare a variable named about_me that creates the following sentence:
#'My hobby is x, my favorite song is y, and I like to eat z.' Where x is hobby, y is fav_song and z is fav_food. Print the about_me variable.
about_me = 'My hobby is ' + hobby + ', my favorite song is ' + fav_song + ', and I like to eat ' + fav_food + '.'
print(about_me)
#3 Spacing with tabs and newlines
#Declare a variable named my_hero that the following sentence using a tab:
#'My hero is x and his famous quote is y.' Where x is role_model and y is famous_quote. Print the my_hero variable.
my_hero = '\tMy hero is ' + role_model + ' and his famous quote is ' + famous_quote + '.'
print(my_hero)
#Declare a variable named my_favs that creates the following sentence and returns a new line after each numbered item.
#'This is what I like: 1. hobby 2. fav_color 3. fav_song
#Print the my_favs variable.
my_favs = 'This is what I like: \n1. ' + hobby + '\n2. ' + fav_color + '\n3. ' + fav_song
print(my_favs)
#4 Variables with a Number value
#Declare variables named age, weight, shoe_size, fav_number, yen_rate, bitcoin_value, todays_temperature, hawaii_popuation, countries_traveled, number_of_siblings
#Assign your own number values to each variable and print each variable.
age = 68
print(age)
weight = 168
print(weight)
shoe_size = 11
print(shoe_size)
fav_number = 3
print(fav_number)
yen_rate = 110
print(yen_rate)
bitcoin_value = 10000
print(bitcoin_value)
todays_temperature = 78.1
print(todays_temperature)
hawaii_popuation = 1200000
print(hawaii_popuation)
countries_traveled = 25
print(countries_traveled)
number_of_siblings = 2
print(number_of_siblings)
#5 Number as Strings Concatenation
#Declare a variable named self_intro that creates the following sentence:
#'Aloha, my name is x and I am y years old and my shoe size is z.' Where x is full_name, y is age and z is shoe_size. Print the self_intro variable.
self_intro = 'Aloha, my name is ' + full_name + ' and I am ' + str(age) + ' years old and my shoe size is ' + str(shoe_size) + '.'
print(self_intro)
#Declare a variable named market_update that creates the following sentence:
#"Today's bitcoin value is x and the yen exchange rate is y." Where x is bitcoin_value and y is yen_rate. Print the market_update variable.
market_update = "Today's bitcoin value is " + str(bitcoin_value) + " and the yen exchange rate is " + str(yen_rate) + "."
print(market_update)
#Declare a variable named about_hawaii that creates the following sentence:
#"Did you know that Hawaii's population is x and the average temperatue is y?" Where x is hawaii_population and y is todays_temperature. Print the about_hawaii variable.
about_hawaii = "Did you know that Hawaii's population is " + str(hawaii_popuation) + " and the average temperature is " + str(todays_temperature) + "?"
print(about_hawaii)
#6 Variables with a List value
#Declare a variable named fab_five and assign it a list containing five of your all time favorite snacks. Print the fab_five variable.
fab_five = ['Oreos', 'carrot cake', 'Pretz', 'peanut butter and chocolate cupcakes', 'pub mix']
print(fab_five)
#Declare a variable named plate_lunch and assign it a list containing five of your favorite lunch items. Print the plate_lunch variable.
plate_lunch = ['chicken katsu', 'kalbi', 'mac salad', 'meat jun','orange chicken']
print(plate_lunch)
#Declare a variable named ice_cream and assign it a list containing three of your favorite ice cream flavors. Print the ice_cream variable.
ice_cream = ['cookies and cream', 'brownie', 'chocolate and peanut butter']
print(ice_cream)
#Declare a variable named west_siiiiide and assign it a list containing states found on the west coast of the US. Print the west_siiiiide variable.
west_siiiiide = ['Washington', 'Oregon', 'California']
print(west_siiiiide)
#Declare a variable named mega_millions and assign it a list containing the Mega Millions Lottery results for May, 4, 2018
#https://www.lotteryusa.com/mega-millions/. Print the mega_millions variable
mega_millions = [4, 5, 10, 12, 18, 21]
print(mega_millions)
#Declare a variable named hamajang and assign it a list containing six different data types. Print the hamajang variable.
hamajang = ['pizza', 100, ['tacos', 'nachos'], {'name': 'Snoopy','breed': 'Beagle'}, ('DevLeague', 'Coding'), True]
print(hamajang)
#Declare a variable named dynamic_duos and assign it a list containing 3 lists, with each list containing items that pairs well with each other. Print the dynamic_duos variable.
dynamic_duos = [['gin', 'tonic'], ['peanut butter', 'celery'], ['bacon', 'cheeseburger']]
print(dynamic_duos)
#Print the following:
#Gin
print(dynamic_duos[0][0])
#peanut butter
print(dynamic_duos[1][0])
#cheeseburger
print(dynamic_duos[2][1])
#7 Accessing values in List
vics_list = ['Hendricks gin', 'Fever Tree tonic', 'Costco pub mix', 'cool ranch doritos', 'oreos', 'Safeway fried chicken', 'Morning Glass coffee']
#Print the entire list.
print(vics_list)
#Print the length of the list.
print(len(vics_list))
#Print only the first element in the list.
print(vics_list[0])
#Print only the last element in the list.
print(vics_list[6])
#Print 'Safeway fried chicken'
print(vics_list[5])
#Replace 'cool ranch doritos' with 'carrot cake' and print the list.
vics_list[3] = 'carrot cake'
print(vics_list)
#Print the last element in the list using -1
print(vics_list[-1])
#8 Variables with a Dictionary value
#Declare a variable named car and create the following key-value pairs:
# - key: brand string value: Tesla,
# - key: model string value: Model 3,
# - key: price number value: 35000,
# - key: color string value: red,
# - key: production boolean value: False,
# - key: features list value: moon roof, leather seats, iphone docker
#Print the car variable.
car = {
'brand': 'Tesla',
'model': 'Model 3',
'price': 35000,
'color': 'red',
'production': False,
'features': ['moon roof', 'leather seats', 'iphone docker']
}
print(car)
#Declare a variable named footwear and create the following key-value pairs:
# - key: brand string value: Vivo Barefoot,
# - key: url string value: https://www.vivobarefoot.com/us,
# - key: gender string value: Mens,
# - key: type string value: Ababa Canvas,
# - key: price number value: 80,
# - key: color list value: tan, black stripes, gum
# - key: ordered boolean value: True
#Print the footwear variable.
footwear = {
'brand': 'Vivo Barefoot',
'url': 'https://www.vivobarefoot.com/us',
'gender': 'Mens',
'type': 'Ababa Canvas',
'price': 80,
'color': ['tan', 'black stripes', 'gum'],
'ordered': True
}
print(footwear)
#Declare a variable named bank and create the following key-value pairs:
# - key: name string value: First Hawaiian Bank,
# - key: employees number value: 2200,
# - key: headquarters string value: Honolulu,
# - key: revenue number value: 700000000,
# - key: nasdaq string value: FHB,
# - key: products list value: savings, loans, trust, wealth management,
# - key: executive dictionary value: name: Robert Harrison, title CEO, salary: 2000000
#Print the bank variable.
bank = {
'name': 'First Hawaiian Bank',
'employees': 2200,
'headquarters': 'Honolulu',
'revenue': 700000000,
'nasdaq': 'FHB',
'products': ['savings', 'loans', 'trust', 'wealth management'],
'executive': {'name': 'Robert Harrison', 'title': 'CEO', 'salary': 2000000}
}
print(bank)
#Declare a variable pandas and assign it an EMPTY dictionary.
#You will add the following key-value pairs:
# - key: name string value: Panda Express
# - key: restaurants number value: 2000
# - key: cuisine string value: Gourmet Chinese Food
# - key: menu list value: Orange Chicken, Walnut Shrimp, Sweet and Sour pork
# - key: highest_revenue string value: Ala Moana Center Food Court
#Print the pandas variable.
pandas = {}
pandas['name'] = 'Panda Express'
pandas['restaurants'] = 2000
pandas['cuisine'] = 'Gourmet Chinese Food'
pandas['menu'] = ['Orange Chicken', 'Walnut Shrimp', 'Sweet and Sour Pork']
pandas['highest_revenue'] = 'Ala Moana Shopping Center Food Court'
print(pandas)
#Declare a variable named bucket_list and assign it to an EMPTY dictionary.
#You will add the following key-value pairs:
# - key: travel string value of your choice
# - key: learn string value of your choice
# - key: weight number value of your choice
# - key: to_dos list value of your choice
# - key: meet_person string value of your choice
#Print the bucket_list variable.
bucket_list = {}
bucket_list['travel'] = 'South Pacific'
bucket_list['learn'] = 'Programming'
bucket_list['weight'] = 168
bucket_list['to_dos'] = ['Hike the Inca Trail to Machu Picchu', 'Visit Angkor Wat','Cruise on a junk boat through Halong Bay']
bucket_list['meet_person'] = 'President Obama'
print(bucket_list)
#9 Variable with a Tuple value
#Declare a variable named bruce_bio and assign a tuple containing the following values: Bruce Lee, male, 32, San Francisco, [Kung-Fu Master, actor, philosopher]
#Print the bruce_bio variable.
bruce_bio = ('Bruce Lee', 'male', 32, 'San Fransico', ['Kung-Fu Master', 'actor', 'philosopher'] )
print(bruce_bio)
#Declare a variable named movies and assign a tuple containing the following values: [The Big Boss, 1971],[Fist of Fury, 1972], [The Way of the Dragon, 1972], [The Game of Death, 1972]
#Print the movies variable.
movies = (['The Big Boss', 1971],['Fist of Fury', 1972], ['The Way of the Dragon', 1972], ['The Game of Death', 1972])
print(movies)
#Declare a variable named updated_bio and add the bruce_bio and movies tuples together. Print the updated_bio variable.
updated_bio = bruce_bio + movies
print(updated_bio)
#Print the following values:
#The length of the updated_bio tuple
print(len(updated_bio))
#Bruce Lee
print(updated_bio[0])
#Index position 1
print(updated_bio[1])
#['Game of Death', 1972]
print(updated_bio[8])
#philosopher
print(updated_bio[4][2])
#1971
print(updated_bio[5][1])
#The Way of the Dragon
print(updated_bio[7][0])
#Fist of Fury
print(updated_bio[6][0])
#The last value using -1
print(updated_bio[-1])
#Game of Death using -1
print(updated_bio[-1][0])
#10 Variables with a Boolean value
#Declare the following variables and assign either a True or false value for each.
#female, american, likes_coding, is_hungry, has_a_dog
#Print each variable that you declare.
female = False
print(female)
american = True
print(american)
likes_coding = True
print(likes_coding)
is_hungry = False
print(is_hungry)
has_a_dog = False
print(has_a_dog)