Python代写:CS177 Lab Prep1 Summer2018

request Description

In this request you will write and submit the labprep1.py program.

Complete and submit the file by the deadline to receive full credit.

Before you Begin

Carefully read the “Coding Standards and Guidelines” shown on the last page of this request.

Your Python programs should follow these standards and guidelines this semester.

Write a Python Program to Calculate the Position of a Tennis ball at a Time Specified

The NASA training academy wants to make use of your superior programming skills to help teach students about the way objects move in a zero gravity environment. They want to simulate the position a tennis ball at a specified time, given an initial velocity. We will assume the acceleration in the horizontal direction is zero, so the velocity will not change over time.

Using the Python IDLE editor, write a program that prompts the user for 2 values:

  • the initial speed (velocity) of the tennis ball
  • the travel time of the ball in space

Using the values entered by the user, calculate and display the distance the ball has traveled.

Steps For This request:

  1. Setup your Python file labprep1.py with an appropriate comments header
  2. Organize labprep1.py using comments for each block of planned code
  3. In each block, write the necessary Python code to complete the task
  4. Save, test, then upload your completed labprep1.py Python program to Blackboard

TO DO #1: Setup Your Python Program File labrep1.py

In Python, the # sign indicates a comment, which documents and organizes your code. Python does not execute these commented lines; they help make the program easier to understand.

In the Python IDLE editor, open a new program window. At the top of the file, create a program header by typing in the following text:

1
2
3
4
5
6
7
#
# CS 177 – labprep1.py
# {insert your name here}
# Following Coding Standards and Guidelines
# This program calculates the distance traveled by a
# tennis ball in space at a time specified by the user
#

TO DO #2: Organize labrep1.py using comments

There are 4 parts to this program:

  1. Display the description of the program
  2. Prompt the user for input values
  3. Calculate the distance traveled by the tennis ball over the time specified
  4. Display the results

Below your program header, enter the following comments (pseudocode) in your Python program identifying each part. Leave blank spaces between each comment.

1
2
3
4
5
6
# Display a message describing the functionality of the program
# Prompt the user for the initial velocity of the ball
# Prompt the user for the time in seconds
# Calculate the distance traveled using the formula:
# distance = velocity * time
# Display the results of the calculation

TO DO #3: Complete the Code

Write appropriate Python code in each section to complete the program by entering commands under the corresponding comment blocks.

Example Input / Output

Your Python program should display a number grid that is organized and easy to read. Below are some example results you can use to test your program. You will only display one result each time you run your program.

TO DO #4: Save and Submit your Completed Python File on Blackboard

Save your Python program using the file name labprep1.py, and submit it before the deadline for full
credit.

  1. Click the Lab Prep 1 request on Blackboard
  2. Click the “Attach File” button
  3. Attach your labprep1.py file
  4. Click submit to complete this request

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#
# CS 177 – labprep1.py
# {insert your name here}
# Following Coding Standards and Guidelines
# This program calculates the distance traveled by a
# tennis ball in space at a time specified by the user
#


# Function: Calculate the distance traveled
# v: velocity
# t: time
# return
# distance = velocity * time
def calc_distance(v, t):
return v * t


# Display a message describing the functionality of the program
print('This program simulates the movement of a tennis ball in space', end='\n')
print('=============================================================', end='\n')
print('It prompts the user for two values:', end='\n')
print('the initial speed of the ball, and a travel time,', end='\n')
print('then computes the position of the ball after that time,', end='\n')
print('=============================================================', end='\n')
print('', end='\n')

# Prompt the user for the initial velocity of the ball
velocity = float(input('Please enter the velocity of the ball (meters per second): '))

# Prompt the user for the time in seconds
time = float(input('Please enter the travel time (seconds): '))

# Calculate the distance traveled using the formula:
# distance = velocity * time
distance = calc_distance(velocity, time)

# Display the results of the calculation
print('', end='\n')
print('After {} seconds the ball is {} meters from the starting point'.format(time, distance))