





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






You must go to your assigned room. If you don’t you will be assigned a 5 point penalty!
x = 14 - 3 ** 3 + 2 % 6 print x
y += y * len(str(y)) y
import math x = ’the answer is ’ + ( str( math.sqrt( 81 ) ) * 3 ) print x
s = ’3’ + ’4’ ’5’ s
int(s) / 10
float(s) / 10
’aBdcSf’.lower().capitalize() + ’BdkgE’.capitalize().lower()
e = [2, 4, 1, 5, 6] e[1] = 8 e.sort() print e
e = [2, 4, 1, 5, 6] f = e[2:4] f[1] = 3 print e, ’\n’, f
making it clear what is your answer:
t = ’ ab c-’ len(t)
x = ’32’ x * len(x)
int(x) / len(x)
a = [ 54, ’abc’, "67.5", 12 ] print a[1]
a[1] = ’def’ print a[1:3]
s = a[2] print s[-1]
name = ’monty python’ name[:-8] + name[9]
sentence = ’the quick brown fox’ print sentence[1:3] * 3 + sentence[-2:] * 3
names = [ ’graham’, ’john’, ’terry’, ’terry’, ’eric’, ’michael’ ] a = str( len( names[0] ) ) + ’2’ b = a + str( len( names[2] + names[-2] ) ) + str( len( names[1] ) ) b
x = 5 y = 12 z = y-x
Please enter your name ==> Jane Q. Public Hello Jane Public!
Hint: you will need to use split
s = spam(3, 10, 4, 2) s ’The average of 3, 10, 4, and 2 is: 4.75’
v = [ 7, 3, 1, 5, 10, 6 ]
then the output of your code should be something like
7 10
If we are given that
v = [ 7 ]
then the output of your code should be
7
def spam(a1,b1,a2,b2): if (a1 == a2) and (b1 > b2): return 1 else: return 0
def egg(a1,b1,a2,b2): if (a1 > a2) and (b1 == b2): return 0 else: return 1
a1 = 3 b1 = 4 a2 = 6 b2 = 4
print spam(a2, b2, a1, b1)
print egg(a1, b1, a2, b2)
c = spam(a1, b2, a2, b1)
print z
c += egg(a1, b2, a2, b1)
print c
v = [ 17, -5, 15, -3, 12, -5, 0, 12, 22, -1 ]
Then the output of your code should be
12 12 15 17 22
As a second example, if
v = [ -17, -5, -15, -3, -12, -5, 0, -12, -22, -1 ]
then then output should be just
None
mylist = [1,4,8,12,6] x = mylist.sort() print x
mylist = [1,4,8,12,6] slice1 = mylist[2:4] slice1[0] = 20 print slice
print mylist
print combine2(’aPPle’, ’BanaNA’) apple banana print combine2(’corN’, ’Candy’) candy corn