Python代写:CS110 Loops

代写Python基础作业,练习loops的使用。

Introduction

For this assignment you will write three short programs.

Reminder

If you talk to someone else (besides the professor) about the assignment, you need to cite this collaboration. If you use any external resources besides class notes and the book, you also need to cite it.

Preliminaries

Log in to gemini and enter these commands to start the project:

cs110
start loops
cd ~/110/loops

This will copy 3 “skeleton programs” to your account. Use the first and third commands above to start each work session. Do not run “start loops” more than once; if you do, it will replace any programs you have written with new blank programs.

Part 1

Filename: ~/110/loops/alphabet.py

The alphabet game is a game played on long car trips, in which the occupants of the car try to find every letter of the alphabet on signs outside of the car. As an adaptation of this game, your task is to write a program that, given a string of text from the user, tells which letters in the alphabet do not appear in the string. Your program should consider both uppercase and lowercase letters to qualify as a letter in the string; in other words, both “A” and “a” as the letter A in the string. Your program should print, in alphabetical order, the uppercase version of the letters that do not appear in the input.

Here is a sample interaction with the program. Bold/underlined values indicate user input.

Enter some text: The quick brown fox ate 4 rotten eggs and said "YUCK!"
Letters not in the text: JLMPVZ

Part 2

Filename: ~/110/loops/ball.py

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 feet bounces 6 feet high, the index is 0.6 and the total distance traveled by the ball is 16 feet after one bounce. If the ball were to continue bouncing, the distance after two bounces would be: 10 ft + 6 ft + 6 ft + 3.6 ft = 25.6 ft note that the ball traveled 16 feet on the first bounce, and 9.6 feet on the second bounce.

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 (10 in this example), its height after the first bounce (6 in this example), and the number of bounces. Output should be the total distance traveled by the ball, rounded to at most 2 decimal places.

Here is a sample interaction with the program:

Enter initial height: 10
Enter height of first bounce: 6
Enter number of bounces: 2
The total distance the ball traveled is 25.6 feet.

Here is another run:

Enter initial height: 20.4
Enter height of first bounce: 9.22
Enter number of bounces: 11
The total distance the ball traveled is 54.04 feet.

Part 3 Filename

~/110/loops/microwave.py
Imagine you are using the timer on a microwave. You enter the time you want to count down from, in minutes and seconds, and the microwave counts down until it reaches 0:00. Your program will, given the minutes and seconds to count down, print the times remaining displayed by the microwave while the timer counts down, with one time on each line. Note: Your program shouldn’t actually take a second between printing each line.

Here is a sample interaction with this program:

Enter the digits as input to the microwave:
0:11
0:11
0:10
0:09
0:08
0:07
0:06
0:05
0:04
0:03
0:02
0:01
0:00

Here is another run of his program (trimmed in the middle for length):

Enter the digits as input to the microwave: 10:03
10:03
10:02
10:01
10:00
9:59
9:58
9:57
...
0:03
0:02
0:01
0:00

And a third example (note that microwaves usually allow you to enter more than 60 seconds):

Enter the digits as input to the microwave: 0:95
0:95
0:94
0:93
0:92
...
0:03
0:02
0:01
0:00

What to hand in Submit your work using the course submission procedure. In this case it is

cd ~/110/loops
submit loops

This will collect the three files: alphabet.py, ball.py, and microwave.py.

Evaluation criteria

Your work will be evaluated according to criteria in two general categories, style and correctness. Each category counts for half of your grade. For this assignment, the criteria are:

  1. Style
    • The header (large docstring at the top) contains all the appropriate information: your name, the name of the file, etc; and that the program description is accurate and complete,
    • The logic (approach to solving the problem) is clear and reasonably simple,
    • Variable names are descriptive, that is, they accurately describe the values they name,
    • Commenting is accurate and complete, and
    • The horizontal and vertical spacing effectively enhances the structure of the program.
    • The program is efficient and avoids redundant computations. If the same calculation is used twice, it is better to do it once and store the result in a variable.
    • No variables are unnecessary. A rule-of-thumb is that a variable is necessary only when it names an important part of the logic, or when it is used in the logic more than once after it is assigned.
  2. Correctness
    • The submission system will evaluate how well your program passes the automatic tests.