Review Questions: Part 3
1.
Write
a function that takes two integers as arguments, called low and high. If low is
less than high, then you should print out all the numbers between low and high
inclusive on one line.
For
example, if low is 6 and high is 14, you should print
6
7 8 9 10 11 12 13 14.
If
low is not less than high, you should print “error, low is not less than high”
(Hint,
if you didn’t use it in the old assignment, see what the following code does:
for
i in range(5,9):
print i
2.
Write
a function that takes one argument: a string with a letter grade and returns
the numeric equivalent according to the following chart
Grade
Numeric
A
4.0
B
3.0
C
2.0
D
1.0
F
0.0
3.
Write
another function that takes one argument that is a string that represents a
letter grade with an optional plus or minus. So the argument could be one of
the following:
″A″, ″A-″, ″B+″, ″B″, ″B-″, ″C+″, ″C″, ″C-″,″D+″, ″D″, ″D-″,″F″
Convert
the grade to its numeric equivalent. A plus adds 0.3 and a minus subtracts 0.3
from the score on the above chart. You
*must* use the function from problem 2 to figure out the letter grade part, and
then add or subtract if necessary.
Hints:
·
What
is: len(“A-“)
·
What
is: len(“A”)
·
Suppose
foo = “Rowan” what is foo[3]
4.
Write
a function called countAZ that takes a 4-letter-long string as an argument and
returns the number of times there is a letter A or a letter Z in that string.
Make sure you count both upper and lower case. You may assume that the string
has EXACTLY 4 letters in it.
Example
1: countAZ(“AzaZ”)
would
return 4
Example
2: countAZ(“Ozob”)
would
return 1
Example
3: countAZ(“coin”)
would
return 0
Hint:
to do this for upper and lower case easily, you could to import the string
class:
from
string import *
Once
you’ve done that, what does upper(“AzaZ”)do to the string “AzaZ”
5. Write a function that takes two strings that each have 4 letters in them, and determines whether there are the same totals of A’s and Z’s in them, and print a message with the answer.
· Note 1: the letters do not have to be the same, there just has to be the same number of them. So “AZbo” and “haha” would be the same.
· Note 2: you should call the function you wrote in part 4 to count the number of A’s and Z’s
Write a function that takes a single argument, and prints out a times table from 1 to 25 for that argument. For example, if your argument was 4, your function would print:
1 * 4 = 4
2 * 4 = 8
3 * 4 = 12
4 * 4 = 16
5 * 4 = 20
6 * 4 = 24
7 * 4 = 28
8 * 4 = 32
9 * 4 = 36
10 * 4 = 40
11 * 4 = 44
12 * 4 = 48
13 * 4 = 52
14 * 4 = 56
15 * 4 = 60
16 * 4 = 64
17 * 4 = 68
18 * 4 = 72
19 * 4 = 76
20 * 4 = 80
21 * 4 = 84
22 * 4 = 88
23 * 4 = 92
24 * 4 = 96
25 * 4 = 100