CS107 Class Assignments Key
Write a program that asks the end-user for an account balance and an interest rate, and then displays what the balance will be after one year. (Introduction to I/O)
Copy your account balance program to another file (e.g., balance2.py). Change the program so that accounts with more than $10,000 pay a rich person fee of $100 yearly (the new balance computed after a year should show this). (Python From NQC)
Write a program factorial which takes in a number from the end-user (using the input() function), and prints out the factorial of that number. Hint: you'll need a while loop. (Python From NQC)
Wri! te a program that reads in 5 numbers from the end-user into a list, then computes the average of those numbers. For this exercise, do not total the numbers as you read them. Instead, use one loop to read in five numbers into a list, and a separate loop to compute the total of the elements in the list. (Introduction to Lists)
In a file mymath.py, write a function 'cube(x)' which returns the cube of the parameter x (x to the 3rd power, or x*x*x).The file's main code should call 'cube(x)' a couple of times with various parameters and print the results. (Functions)
In mymath.py, import the math module and rewrite cube(x) so that it calls the math.pow function within it. (Functions)
Write a program redEvenRows.py that draws red lines on every other row in a picture. You'll use a nested loop like above, but change the increment from 1. (Media Computing: Manipulating Pixels)
Write a program lighten.py that lightens all pixel in a pic. (Media Computing: Manipulating Pixels)
Use Google Im! age search to download an image of a beach scene, one that's bright and sunny. Then write a program sunset.py that turns it into a sunset scene (hint: one way to do it is to reduce the blue and green of each pixel). (Media Computing: Manipulating Pixels)
Write a program grayscale.py to turn a color picture to black and white. You can turn a picture into black and white (grayscale) by modifying it so that all pixels have values such that red=green=blue. One formula for figuring out how dark each pixel should be is: intensity = (red + green + blue)/3 where red, green, and blue are the values of the pixel in the picture with color. (Media Computing: Manipulating Pixels)
Write a program that mirrors the left-side of an image onto the right side of the ! image. Test it with a 'main' that opens a pic and mirrors it.(Media Computing: Manipulating Pixels)
Write a program that loads the image at http://cs.usfca.edu/~wolber/courses/110/JES/giantsScoreBoard.gif, then draws a personalized welcome greeting of your choice on the scoreboard. You may want to use the function "addRectFilled(pic,startx,starty,width,height,color)" as well as addText. For full credit, write the program using a function with a parameter that is the specific name to be drawn. (Media Computing: Manipulating Pixels)
Introduction to I/O -
http://www.cs.usfca.edu/~wol! ber/courses/107/lectures/pythonio.htm
Python From NQC -
http://www.cs.usfca.edu/~wolber/courses/107/lectures/PythonLoopsIfVar.html
Introduction to Lists -
http://www.cs.usfca.edu/~wolber/courses/107/lectures/lists.html
Functions -
http://www.cs.usfca.edu/~wolber/courses/107/lectures/functions.htm
Media Computing: Manipulating Pixels -
http://www.cs.usfca.edu/~wolber/courses/107/lectures/manipPixels.htm