a) Let string s be defined as: s = \'Welcome to Python Programming\' Write Pytho
ID: 3817181 • Letter: A
Question
a) Let string s be defined as:
s = 'Welcome to Python Programming'
Write Python Boolean expressions that correspond to these propositions:
a) The slice consisting of the 12th and 13th character of s is 'Py'.
b) The slice consisting of the 8th thru 11th character of s is 'gram'.
c) The slice consisting of characters from -23 to -40 is 'Welcome'.
d) The slice of s excluding the first 11 characters and the last 12 characters is 'Python'.
b) Let string s be defined as: s = 'Welcome to Python Programming'
a) Write Python statement that strips of characters and prints the word ‘Python’
b) Write Python statement that strips of characters and prints the word ‘Welcome’
c) Let string s be defined as: s = 'abcdefghijklmnopqrstuvwxyz'
Build the words ‘great’ and ‘python’ from the above string of characters. You may use split, indexing operator, slice, or any other string function
Explanation / Answer
# a) Let string s be defined as:
# s = 'Welcome to Python Programming'
s = 'Welcome to Python Programming'
# Please note indexing start at 0 and not 1 in python
# slicing is [start:end] where end charcter is not included
print s[11:13] == 'Py' # a. True
print s[7:12] == 'gram' # b. False
print s[-40:-22] == 'Welcome' # c. True
print s[11:-12] == 'Python' # d. True
# b) Let string s be defined as: s = 'Welcome to Python Programming'
s = 'Welcome to Python Programming'
print s[11:-12] # a. print Python
print s[:7] # b. print Welcome
# c) Let string s be defined as: s = 'abcdefghijklmnopqrstuvwxyz'
s = 'abcdefghijklmnopqrstuvwxyz'
print s[6] + s[17] + s[4] + s[0] + s[19] # prints great
print s[15] + s[24] + s[19] + s[7] + s[14] + s[13] # prints python
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.