-
Notifications
You must be signed in to change notification settings - Fork 0
/
3. Filter by Type
66 lines (57 loc) · 1.95 KB
/
3. Filter by Type
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
#Assignment: Filter by Type
Write a program that, given some value, tests that value for its type. Here's what you should do for each type:
Integer
If the integer is greater than or equal to 100, print "That's a big number!" If the integer is less than 100, print "That's a small number"
String
If the string is greater than or equal to 50 characters print "Long sentence." If the string is shorter than 50 characters print "Short sentence."
List
If the length of the list is greater than or equal to 10 print "Big list!" If the list has fewer than 10 values print "Short list."
Test your program using these examples:
sI = 45
mI = 100
bI = 455
eI = 0
spI = -23
sS = "Rubber baby buggy bumpers"
mS = "Experience is simply the name we give our mistakes"
bS = "Tell me and I forget. Teach me and I remember. Involve me and I learn."
eS = ""
aL = [1,7,4,21]
mL = [3,5,7,34,3,2,113,65,8,89]
lL = [4,34,22,68,9,13,3,5,7,9,2,12,45,923]
eL = []
spL = ['name','address','phone number','social security number']
copy
Hint: You might want to read about the type and isinstance functions.#
sI = 45
mI = 100
bI = 455
eI = 0
spI = -23
sS = "Rubber baby buggy bumpers"
mS = "Experience is simply the name we give our mistakes"
bS = "Tell me and I forget. Teach me and I remember. Involve me and I learn."
eS = ""
aL = [1,7,4,21]
mL = [3,5,7,34,3,2,113,65,8,89]
lL = [4,34,22,68,9,13,3,5,7,9,2,12,45,923]
eL = []
spL = ['name','address','phone number','social security number']
# set one of the above variables as the current one I'm testing
current_tester = lL
curr_type = type(current_tester)
if curr_type is int:
if current_tester >= 100:
print "That's a big number!"
else:
print "That's a small number!"
elif curr_type is str:
if len(current_tester) >= 50:
print "Long sentence."
else:
print "Short sentence."
elif isinstance(current_tester, list):
if len(current_tester) >= 10:
print "Big list!"
else:
print "Short list."