Skip to content

Commit de50282

Browse files
authoredFeb 23, 2021
Add files via upload
1 parent e02d210 commit de50282

File tree

5 files changed

+143
-74
lines changed

5 files changed

+143
-74
lines changed
 

‎Section_02/assignment_01.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Assignment 1:
22
"""
3-
Print Bill's salary from the my_list object shown below.
4-
5-
my_list = [{'Tom': 20000, 'Bill': 12000}, ['car', 'laptop', 'TV']]
3+
We would like to get the remainder of 15 divided by 4.
4+
The calculation below does not seem to give us this result.
5+
How would you change the code to meet the requirement?
66
77
"""
88

99

10-
# your code below:
1110

1211

1312

@@ -42,5 +41,11 @@
4241

4342

4443

45-
# Solution
46-
# print(my_list[0].get('Bill'))
44+
45+
46+
47+
# Solution:
48+
49+
# remainder = 15 % 4
50+
# print(remainder)
51+

‎Section_02/assignment_02.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,13 @@
11
# Assignment 2:
22
"""
3-
Using some of the collection data types we learned about
4-
in the course so such as a list and dictionary, create a
5-
data structure that best represents the following scenario:
6-
7-
Tom has a salary of 20000 and is 22 years old. He owns a few items such as
8-
a jacket, a car, and TV. Mike is another person who makes 24000 and is 27 years old
9-
who owns a bike, a laptop and boat.
10-
"""
11-
12-
# your code below:
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-
3+
Use of the below format() method is incorrect for what we are trying to do.
4+
We actually have 10 small, 12 large, and 12 medium boxes.
5+
Write code to correct this:
396
407
8+
print("We have {2} small boxes, {2} large boxes, {2} medium boxes".format(10,12,12))
419
10+
"""
4211

4312

4413

@@ -52,7 +21,4 @@
5221

5322

5423

55-
# Solution
5624

57-
# my_list = [{'Tom': {'salary': 20000, 'age': 22, 'owns': ['jacket', 'car', 'TV']}},
58-
# {'Mike': {'salary': 24000, 'age': 27, 'owns': ['bike', 'laptop', 'boat']}}]

‎Section_02/assignment_03.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
# Assignment 3:
22
"""
3-
There is a list shown below titled original_list.
3+
Given 2 variables chars and word, write code to move
4+
the data contained in the variable word in the exact middle of
5+
the characters contained in the variable chars and save this
6+
in a new variable called result and print it.
47
5-
Using only what you've learned so far in the course,
6-
write code to create a new list that contains the tuple sorted.
8+
NOTE: chars variable will contain only 4 characters
79
8-
IMPORTANT: you must do this programmatically! Don't just
9-
hard code a new list with the values rearranged.
10-
"""
11-
12-
original_list = ['cup', 'cereal', 'milk', (8, 4, 3)]
10+
Example:
11+
---------------
12+
chars = "<<>>"
13+
word = "hello"
14+
result - should contain the following string: <<hello>>
1315
14-
# your code below:
16+
"""
1517

18+
chars = "[[]]"
19+
word = "Cool"
1620

21+
# Expected Result Printed: [[Cool]]
1722

23+
# Your code below:
1824

1925

2026

@@ -47,15 +53,7 @@
4753

4854

4955

56+
# Solution Below:
57+
# print(chars[:2] + word + chars[2:])
5058

5159

52-
# Solution
53-
# num1 = original_list[3][0]
54-
# num2 = original_list[3][1]
55-
# num3 = original_list[3][2]
56-
# new_list = [num1, num2, num3]
57-
# new_list.sort()
58-
# new_tuple = (new_list[0], new_list[1], new_list[2])
59-
# new_list = [original_list[0], original_list[1], original_list[2], new_tuple]
60-
#
61-
# print(new_list)

‎Section_02/assignment_04.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
11
# Assignment 4:
22
"""
3-
In the list shown below, replace the letter m with the letter x
4-
and replace the word TV with the word television. Then print my_list.
3+
Given 2 variables word1 and word2, write code to
4+
print the concatenation of the 2 words omitting the
5+
first_folder letter of the string saved in word1 and the second_folder
6+
letter of the string saved in word2.
7+
8+
Example:
9+
---------------
10+
word1 = "Vehicle"
11+
word2 = "Robot"
12+
result - ehicleRbot
13+
514
"""
615

7-
my_list = [(1, 2), (3, 4), (['c', 'd', 'a', 'm'], [3, 9, 4, 12], 4), 'TV', 42]
16+
word1 = "Computer"
17+
word2 = "Truck"
18+
19+
# Expected Result Printed: omputerTuck
20+
21+
# Your code below:
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
846

947

10-
my_list[2][0][3] = 'x'
11-
my_list[3] = 'Television'
1248

13-
print(my_list)
1449

1550

1651

@@ -21,9 +56,8 @@
2156

2257

2358

59+
# Solution Below:
60+
# result = word1[1:] + word2[0:1] + word2[2:]
61+
# print(result)
2462

2563

26-
# Solution:
27-
# my_list[2][0][3] = 'x'
28-
# my_list[3] = 'Television'
29-
# print(my_list)

‎Section_02/assignment_05.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Assignment 5:
2+
"""
3+
Given 2 variables chars and word, write code to move
4+
the data contained in the variable word in the exact middle of
5+
the characters contained in the variable chars and save this
6+
in a new variable called result and print it.
7+
8+
NOTE: chars variable can contain any even number of characters.
9+
the len() function can be used to figure out the length of a string
10+
11+
Example:
12+
---------------
13+
chars = "<[<||>]>"
14+
word = "mirror"
15+
result - should contain the following string: <[<|mirror|>]>
16+
17+
"""
18+
19+
chars = "<<[]]]" # this could be a very long string with an even length.
20+
word = "Cool"
21+
22+
# Expected Result Printed: <<[Cool]]]
23+
24+
25+
# Your code below:
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+
# Solution Below:
62+
# size = len(chars)
63+
# idx = int(size/2) # dividing results in a float datatype.
64+
# print(chars[:idx] + word + chars[idx:])
65+
66+

0 commit comments

Comments
 (0)
Please sign in to comment.