Write a function called convert_grade(numeric_grade)
,
which takes an integer in the range \((0, 5)\). Your function
should print the letter grade the user recieved, given the numeric grade:
Numeric Grade | Letter Grade |
---|---|
0 | F |
1 | D |
2 | C |
3 | B |
4 | A |
>>> convert_grade(0) F >>> convert_grade(1) D >>> convert_grade(4) A
You are directly given an integer as input. You simply need to convert this integer into a string. There are many ways to do this, but the easiest to understand is likely using if statements.
For each entry in the table above, you need one if statement. if the numeric value equals 4, then output A, etc.
Don't forget, to compare equality you want to use
the ==
operator.
Write a function called print_factors(x)
, which prints
all of the positive integer factors of \(x\). An integer \(y\) is an integer
factor of \(x\) if the remainder of \(\frac{x}{y}\) is 0.
>>> print_factors(1) 1 >>> print_factors(2) 1 2 >>> print_factors(4) 1 2 4
The remainder operator in Python is \(\%\). \( x \% y == 0\) tells you that y evenly divides x.
Write a loop that goes through all of the integers greater than 1, but less than (or equal to) \(x\). See if the above condition is true. If it is true, print the loop variable.
In a file called blurred_images.py write a function
called simple_blur(a_picture)
. This function should
display a blurred version of the image parameter.
To blur an image, you simply average a pixels color value with the 4 pixels surrounding it.
Note: This image has actually been blurred 4 times, to make it obvious what is happening. Your image will only be slightly fuzzy.
You need to iterate over the pixels of your image for this
assignment. However, you need to know the x and y locations of
each pixel. You can either use the nested for loop to
get x and y coordinates, or you can use
the getX(pixel)
and getY(pixel)
functions to get your coordinates.
You also need to get the 4 pixels surrounding your current
location. You can use the getPixelAt(a_picture, x,
y)
function to get a pixel at a specific location from
the picture. You simply need to add and subtract 1 from x and y
each.
For each of these 4 surrounding pixels, you want
to getRed
, getGreen
,
and getBlue
. You will compute the average of each of
those values, and use setRed
, setGreen
,
and setBlue
to set the color of the pixel.