4 2mod7
4 2mod7
ipynb - Colaboratory
Section 4.2
Nested Conditionals
Nested conditionals
Print formatting with the () escape sequence
Escape Sequences
Escape sequences all start with a backslash ( \ )
Escape sequences can be used to display characters in Python reserved for formatting
\\ Backslash ( \ )
\' Single quote (')
\" Double quote (")
\t Tab
\n return or newline
Examples
Hello World!
I am formatting print
"quotes in quotes"
I've said "save your notebook," so let's do it!
for a newline use \n
https://colab.research.google.com/drive/1ReOVE-6HJPBvkU2ymbqQqKheBiEUBkBs#scrollTo=qAB-zaRayrdq&printMode=true 1/3
3/6/23, 11:55 AM 40460_Mod04_4.2 (1) (1).ipynb - Colaboratory
# [ ] print "\\\WARNING!///"
print("\\\WARNING!///")
\\WARNING!///
# [ ] print output that is exactly (with quotes): "What's that?" isn't a specific question.
print("\"What's that?\"isn't a specific question")
# [ ] from 1 print statement output the text commented below using no spaces
# One Two Three
# Four Five Six
print("One\tTwo\tThree\nFour\tFive\tSix")
Get input using the directions: *enter a word that starts with "pre": *
Call pre_word() with the input string
Test if return value is False and print message explaining not a "pre" word
else print message explaining is a valid "pre" word
def pre_word(check):
if check.isalpha:
print("Is alphabetical")
else:
print("Is not alphabetical")
if check.startswith("pre"):
print("Starts with pre")
else:
print("Doesn't start with pre")
return check
pre_word(check1)
Hello
World!
https://colab.research.google.com/drive/1ReOVE-6HJPBvkU2ymbqQqKheBiEUBkBs#scrollTo=qAB-zaRayrdq&printMode=true 2/3
3/6/23, 11:55 AM 40460_Mod04_4.2 (1) (1).ipynb - Colaboratory
Created in Deepnote
https://colab.research.google.com/drive/1ReOVE-6HJPBvkU2ymbqQqKheBiEUBkBs#scrollTo=qAB-zaRayrdq&printMode=true 3/3