# 111 lab2

Computer Science 111 – Fundamentals of Programming IProgramming Project 2

Due 11:59 PM, Friday 25 September

Warmup

Formatting text for output is discussed in Section 3.2 of the text. Launch idle3 and enter the following expressions at the shell prompt (one line at a time, ignoring the comments):

“34” 34

“%3d” % 34 # Right justified in 3 columns “%-3d” % 34 # Left justified in 3 columns
(34, 22)# A tuple of 2 elements
“%3d%4d” % (34, 22)# Right justify 2 data values print(“%3d%4d” % (34, 22)) # Strip the quotes pi = 3.1416 # Define pi

“%0.3f” % pi # 3 digits of precision

“%6.3f” % pi # Right justify also

print(2.00) # Try to get 2 places

print(“%0.2f” % 2.00) # Get them for sure

for x in range(30):# Print 30 powers of 2 print(x, 2 ** x)

```   for x in range(30):# Print 30 powers of 2,
print("%-4d%9d" % (x, 2 ** x)) # nicely formatted
```

To Turn in

Create a project2 directory in your Home directory. Launch idle3 and complete the following exercises. Save the solution to each exercise in an appropriately named file.Each file should include a prefatory dosctring (using the triple quotes) with your name, project number, file name, and a brief description of what the program does (including inputs and outputs). Be sure to test your programs with several inputs and suitably label your outputs.

1. Teachers in most school districts are paid on a schedule that provides a salary based on their number of years of teaching experience. For example, a beginning teacher in the Lexington School District might be paid \$30,000 the first year. For each year of experience after this first year, up to 10 years, the teacher receives a 2% increase over the preceding value. Write a program that displays a salary schedule, in tabular format, for teachers in a school district. The inputs are the starting salary, the percentage increase, and the number of years in the schedule. Each row in the schedule should contain the year number and the salary for that year. Each column should have a descriptive heading in the first row.
2. A standard science experiment is to drop a ball and see how high it bounces. Once the “bounciness” of the ball has been determined, the ratio gives a bounciness index. For Example, if a ball dropped from a height of 10 meters bounces 6 meters high, the index is 0.6 and the total distance traveled by the ball is 16 meters after one bounce. If the ball were to continue bouncing, the distance after two bounces would be 10 m + 6 m + 6 m + 3.6 m = 25.6 m. Note that distance traveled for each successive bounce is the distance to the floor plus 0.6 of that distance as the ball comes back up. Write a program that lets the user enter the initial height of the ball, its bounciness index, and the number of times the ball is allowed to continue bouncing. Output should be the total distance traveled by the ball. For 5 points extra credit, can you come up with aclosed form (non-looping, not using sum) solution for the total distance, as we did with the compound-interest formula for bank balance in class? If you can, add a line of code to your program reporting the distance computed using this method. You may have to modify your original code somewhat, in order to see the same result in both methods. Hint: mathematicians call this a finite geometric series. Google it – and be sure to add a comment containing the URL of the page that you used.
3. Extra credit (5 points). Copy and unzip the circle folder from the course webpage to your account. Run the circlewithgui program and study the code. Make a copy of that file named sphereproperties, and modify the code so that it displays the diameter, circumference, surface area, and volume of a sphere. The output fields should be read-only, and the outputs should include two figures of precision. Place the updated circle folder in your project2 folder for turnin.