Midterm: ITEC 2120; Spring 2015; Dr. Jim Rowan

advertisement
Midterm: ITEC 2120; Spring 2015; Dr. Jim Rowan
(117 points total)
string, integer, float, boolean or list?
(2Points each)
1) variable1 = “This is a test! ”
2) variable2 = “True”
3) variable3 = variable1 + variable2
4) variable4 = 10
5) variable5 = True
6) variable6 = “False”
7) variable7 = 7.0
8) variable8 = [ ]
9) variable9 = “a what? “
10) variable10 = False
11) variable11 = “a test! “
12) variable12 = [variable1, variable9, variable11]
13) variable13 = variable1.split(“ “)
14) variable14 = True or False
15) variable15 = 9.0 / 5
True or False?
(the variables, variable1, variable2… are defined in the first section above, questions 1 - 15)
(2Points each)
1) variable4 != 10
2) variable4 > 10
3) variable4 ==10 and variable6 == “False”
4) not (variable4 == 10)
5) variable4 == 10 or variable10 == True
valid variable name?
(2Points each)
1) this_is_it
2) this is that
3) this-and-that
4) this/and/the/other/thing
5) that’sAll.I’mDone!
6) 8isEnough
7) xLr8
8) return
9) AND_ANOTHER_THING
what will be printed?
(the variables, variable1, variable2… are defined in the first section above, questions 1 - 15)
(2Points each)
1) print len(variable1)
2) print len(variable12)
3) print variable11[0].upper() + variable11[1:len(variable11)]
4) print variable4 % 2
5) print variable7 % 2
6) print 8 / 3
what will happen?
(5Points each)
1) If the following code were to execute, what would print?
var1 = 1
for x in range(0,5):
var1 = var1 + 1
print var1
2) If the following code were to execute, what would print?
var1 = 0
for x in range(0,5):
var1 = var1 + x
print var1
3) What will print after executing this code?
var2 = 45
var3 = 67.3
if type(var2) == float:
print "var2 is a float"
elif type(var3) == float:
print "var3 is a float"
4) What will print after executing this code?
var2 = 45
var3 = 67.3
if type(var2) == int:
print "var2 is an int"
elif type(var3) == float:
print "var3 is an int"
5) What will print after executing this code?
var5 = "The best way to predict the future"
var6 = "is to invent it"
print "%s%s%s" % (var5, " ", var6)
6) What will print after executing this code?
var5 = "The best way to predict the future"
var6 = "is to invent it"
print "%s\n%s" % (var5, var6)
coding
1) (2Points) Write all the code necessary to allow a person at the keyboard to enter a string and
then print that string.
2) (10Points) Write all the code necessary to allow a person to enter a number grade (from 0 to
100) on the keyboard and then print out the corresponding letter grade according to the
following grade guidelines.
90-100 A
80-89 B
70-79 C
60-69 D
otherwise F
3) (5Points) Write a for-loop that prints out all the numbers from 1 to 15 on separate lines,
printing one line per loop execution.
Download