small medium large xlarge

# Working with Text

1.

a.'ComputerScience'
b."Darwin's"
c.'H2OH2OH2O'
d.''

2.

a. "They'll hibernate during the winter."
b. '"Absolutely not," he said."
c. '''"He said, 'Absolutely not,'" recalled Mel.'''
d. 'hydrogen sulfide'
e. 'left\\right'

3.

'A\nB\nC'

4.

>>> len('')
0


5.

a. print('The rabbbit is ' + str(x) + '.')
b. print('The rabbbit is', x, 'years old.')
a. print(y, 'is average.')
a. print(y, '*', x)
a. print(str(y) + ' * ' + str(x) + ' is ' + str(y * x) + '.')

6. Doe, John

7.

num = float(input())
print(num)


8.

def repeat(s, n):
""" (str, int) -> str

Return s repeated n times; if n is negative, return the empty string.

>>> repeat('yes', 4)
'yesyesyesyes'
>>> repeat('no', 0)
''
>>> repeat('no', -2)
''
>>> repeat('yesnomaybe', 3)
'yesnomaybeyesnomaybeyesnomaybe'
"""
return s * n


9.

def total_length(s1, s2):
""" (str, str) -> int

Return the sum of the lengths of s1 and s2.

>>> total_length('yes', 'no')
5
>>> total_length('yes', '')
3
>>> total_length('YES!!!!', 'Noooooo')
14
"""
return len(s1) + len(s2)

Page History
• V11: Paul Gries [over 3 years ago]
• V10: Jennifer Campbell [over 3 years ago]
• V9: Jennifer Campbell [over 3 years ago]
• V8: Jennifer Campbell [over 3 years ago]
• V7: Jennifer Campbell [over 3 years ago]
• V3: Jennifer Campbell [over 3 years ago]
• V6: System [over 3 years ago]
• V5: System [over 3 years ago]
• V4: System [over 3 years ago]
• V2: Jason Montojo [over 3 years ago]