Write Python expressions corresponding to these statements: (f) \'+–+++––+–+++––
ID: 3737271 • Letter: W
Question
Write Python expressions corresponding to these statements:
(f) '+–+++––+–+++––+–+++––+–+++––+–+++––' Try to make your string expressions as succinct as you can. 2.14 Start by running, in the shell, the following assignment statement: >>> s = 'abcdefghijklmnopqrstuvwxyz' Now write expressions using string s and the indexing operator that evaluate to 'a', 'c', 'z', 'y', and 'q'. 2.15 Start by executing s = 'goodbye' Then write a Boolean expression that check whether: (a) The first character of string s is 'g' (b) The seventh character of s is g (c) The first two characters of s are g and a (d) The next to last character of s is x (e) The midle character of s is d (f) The first and last characters of string s are equal (g) The last 4 characters of string s match the string 'tion' Note: These seven statements should evaluate to True, False, False, False, True, False, and False, respectively. 2.16 Write the corresponding Python assignment statements: (a) Assign 6 to variable a and 7 to variable b. (b) Assign to variable c the average of variables a and b. Chapter 2 Exercises 49 (c) Assign to variable inventory the list containing strings 'paper', 'staples', and 'pencils'. (d) Assign to variables first, middle and last the strings 'John', 'Fitzgerald', and 'Kennedy'. (e) Assign to variable fullname the concatenation of string variables first, middle, and last. Make sure you incorporate blank spaces appropriately.
Explanation / Answer
Solution:
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
s= 'abcdefghijklmnopqrstuvwxyz'
Expressions=>
s[0]
s[2]
s[25]
s[24]
s[16]
s= 'goobye'
a)
if (s[0]=='g'):
b)
if (s[6]=='g'):
c)
if (s[0]=='g' and s[0]=='a'):
d)
if (s[len(s)]-1=='x' ):
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.