-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssign3.py
More file actions
64 lines (46 loc) · 1.16 KB
/
Assign3.py
File metadata and controls
64 lines (46 loc) · 1.16 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
#Answers for Assignment3 218029604 Tsetse CK
#python Assign3.py
#PROBLEM 1
#Given the string
s='fullstackslp'
#use the indexing to print out the following
#f
print(s[0])
#p
print(s[11])
#stack
print(s[4:9])
#slp
print(s[9:12])
#cks
print(s[7:10])
#reverse string
s = 'fullstackslp'[::-1]
print(s)
#PROBLEM2 LISTS
#Given this nested list:
l=[3,7,[5,[1,4,'hello']]]
#Reassign "hello" to be "goodbye"
l[2][1][2]='goodbye'
print(l)
#PROBLEM3 DICTIONARIES
#using keys and indexing, grab 'hello' from the following dictionaries
d1={'simple_key':'hello'}
print(d1['simple_key'])
d1={'k1':{'k2':'hello'}}
print(d1['k1']['k2'])
d1={'k1':[{'nest_key':['this is deep',['hello']]}]}
print(d1['k1'][0]['nest_key'][1])
#PROBLEM4 SETS
#use a set to find the unique values pf the list below
mylist=[1,1,1,1,1,2,2,2,2,3,3,3,3]
new_list=set(mylist)
print(new_list)
#PROBLEM 5 FORMATTING
#Given the variables
age=49
name="Kyle"
#use print formatting to print the following string
#Hello my name's dog is Kyle and he looks 45 years old
mystring="Hello my name's dog is {} and he looks {} years old".format(name,age)
print(mystring)