demo_strings.py
and save it to your cs100/ch3
folder.myCourse = "CS100 Scientific Computing"
. For the following questions, write code to check your answer, and write your answer in comments next to it.
myCourse
?print( myCourse[-9:-5])
print( myCourse[17:21])
print( myCourse[17] )
?'S'
in myCourse
, and what command do you use to find it?print('100' in myCourse)
?print('130' not in myCourse)
?print('wow'*5)
?print( ('.'*3 + 'y')*3 )
?myCourse
with "Exam 1"
.myCourse
string so that it is center justified and takes up 40 characters of space. Hint: use the center
function.f
.
f
to print out the last 5 characters of f
.f
to print out the substring ātasticā.s = input('Type something here: ') # <-- do not change this part
print(s)
s
to print only the first 5 characters from the string the user typed in.s
using the len
function.book
and assign it the string you copied. Itās a very long string, so we will use notation to start and end a multiline string ("""
). For example:
book = """
put all pasted text here
....
it will span many lines
all of this is still a string
"""
book
to answer the following questions. Print your results.
countACGT(seq)
that displays the number of a
, c
, g
, and t
characters that occur in a DNA sequence. Call your function to test it with the string āaactTtgttActā (note the upper and lowercase characters). For example, calling the function countACGT('aactTtgttAct')
should display:
No. of A: 3
No. of C: 2
No. of G: 1
No. of T: 6
Other letters: 0
countLetters(s)
that takes a string s
and counts the number of vowels and consonants in it, printing the result. For example, calling the function countLetters("Hello World")
should display:
Hello World
Number of consonants: 7
Number of vowels: 3
titleCapitalization(s)
which takes a string s
and returns a new string in which the first letter of every word in s
is capitalized. This function should use a for loop to go through each character, gradually building a string to return. If the character is the first letter of a word (i.e. the first letter of the string or the first letter after a space), then it uses the upper()
function to make the letter capitalized. For example, calling the function:
t = titleCapitalization("this title is great")
print(t) #outputs "This Title Is Great"
Submit your working python file to Moodle.