-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart6_Exercise_Review.py
More file actions
83 lines (57 loc) · 1.49 KB
/
Copy pathPart6_Exercise_Review.py
File metadata and controls
83 lines (57 loc) · 1.49 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
#####################################
#### PART 6: EXERCISE REVIEW #######
#####################################
# Time to review all the basic data types we learned! This should be a
# relatively straight-forward and quick assignment.
###############
## Problem 1 ##
###############
# Given the string:
s = 'django'
# Use indexing to print out the following:
# 'd'
print(s[0])
# 'o'
print(s[5])
# 'djan'
print(s[0:4])
# 'jan'
print(s[1:4])
# 'go'
print(s[4:])
# Bonus: Use indexing to reverse the string
['d','o','djan','jan','go']
###############
## Problem 2 ##
###############
# Given this nested list:
l = [3,7,[1,4,'hello']]
# Reassign "hello" to be "goodbye"
l[2][2] = 'goodbye'
print(l)
###############
## Problem 3 ##
###############
# Using keys and indexing, grab the 'hello' from the following dictionaries:
d1 = {'simple_key':'hello'}
print(d1['simple_key'])
d2 = {'k1':{'k2':'hello'}}
print(d2['k1']['k2'])
d3 = {'k1':[{'nest_key':['this is deep',['hello']]}]}
# print(d3['k1'][{'nest_key'}]['this is deep'])
###############
## Problem 4 ##
###############
# Use a set to find the unique values of the list below:
mylist = [1,1,1,1,1,2,2,2,2,3,3,3,3]
mylisty = set(mylist)
print(mylisty)
###############
## Problem 5 ##
###############
# You are given two variables:
age = 4
name = "Sammy"
# Use print formatting to print the following string:
"Hello my dog's name is Sammy and he is 4 years old"
print("Hello my dog's name is " + str(name) + "and he is " + str(age) + 'years old' )