-
Notifications
You must be signed in to change notification settings - Fork 242
/
wk6 - quiz.py
116 lines (90 loc) · 1.74 KB
/
wk6 - quiz.py
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
Question 1
What does the following Python Program print out?
str1 = "Hello"
str2 = 'there'
bob = str1 + str2
print(bob)
Hello
Hellothere
0
Hello
there
Answer: Hellothere
Question 2
What does the following Python program print out?
x = '40'
y = int(x) + 2
print(y)
42
x2
402
int402
Answer: 42
Question 3
How would you use the index operator [] to print out the letter q from the following string?
x = 'From [email protected]'
print(x[9])
print(x[q])
print(x[-1])
print(x[7])
print(x[8])
Answer: print(x[8])
Question 4
How would you use string slicing [:] to print out 'uct' from the following string?
x = 'From [email protected]'
print(x[14:3])
print(x[14+17])
print(x[15:18])
print(x[14:17])
print(x[14/17])
print(x[15:3])
Answer: print(x[14:17])
Question 5
What is the iteration variable in the following Python code?
for letter in 'banana' :
print(letter)
for
letter
print
'banana'
in
Answer: letter
Question 6
What does the following Python code print out?
print(len('banana')*7)
-1
banana banana banana banana banana banana banana
0
42
Answer: 42
How would you print out the following variable in all upper case in Python?
greet = 'Hello Bob'
puts greet.ucase;
console.log(greet.toUpperCase());
print(uc($greet);)
print(greet.upper())
Answer: print(greet.upper())
Question 8
Which of the following is not a valid string method in Python?
join()
upper()
twist()
lstrip()
Answer: twist
Question 9
What will the following Python code print out?
data = 'From [email protected] Sat Jan 5 09:14:16 2008'
pos = data.find('.')
print(data[pos:pos+3])
.ma
mar
Sat
09:14
Answer: .ma
Question 10
Which of the following string methods removes whitespace from both the beginning and end of a string?
strip()
wsrem()
strtrunc()
split()
Answer: strip()