Write a program to provide information on the height of a ball thrown straight up into the air. The program should request as input the initial height, h feet, and the initial velocity, v feet per second. The height of the ball after t seconds is, in feet: h + vt – 16t2 --

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
How do you do this? Comment explanation for each code of line please
Write a program to provide information on the height of a ball
thrown straight up into the air, The program should request as
input the initial height, h feet, and the initial velocity, v feet per
second. The height of the ball after t seconds is, in feet:
h+ vt- 16t2
The program should perform the following two calculations:
1. Determine the maximum height of the ball. Note: The ball
will reach its maximum height after v/32 seconds.
2. Determine the approximately when the ball will hit the
ground. Hnt. Calculate the height after every 0.01 second
and determine when the height is not longer a positive
number.
A function named getinput should be used to obtain the values
of h and v and that function should calla function named isValid
to ensure that the input values are positive numbers. Each of
the tasks 1 and 2 should be carried out by functions. Also within
one of your function you must use the return feature (vou can
use this feature in all functions if you want as well). Below is
example of the inputs and outputs that you could get:
Transcribed Image Text:Write a program to provide information on the height of a ball thrown straight up into the air, The program should request as input the initial height, h feet, and the initial velocity, v feet per second. The height of the ball after t seconds is, in feet: h+ vt- 16t2 The program should perform the following two calculations: 1. Determine the maximum height of the ball. Note: The ball will reach its maximum height after v/32 seconds. 2. Determine the approximately when the ball will hit the ground. Hnt. Calculate the height after every 0.01 second and determine when the height is not longer a positive number. A function named getinput should be used to obtain the values of h and v and that function should calla function named isValid to ensure that the input values are positive numbers. Each of the tasks 1 and 2 should be carried out by functions. Also within one of your function you must use the return feature (vou can use this feature in all functions if you want as well). Below is example of the inputs and outputs that you could get:
Expert Solution
Step 1

def getInput():
  # The above line
  # we define a fucntion 
  # of name getInput()
 
  
  hei = int(input("The starting(initial) height of the ball Please provide:"))
 
  # input of integer from the User
  # and stored in hei which is height
  vel = int(input("The starting(initial) velocity of the ball Please provide :"))
 
  # input of integer from the User
  # and stored in vel which is velocity
  isValid(hei,vel)
  # The above is we called isValid() function
  # With two arguments like hei and vel 
  # velocity and height repectively
def isValid(hei,vel):
  # The above is we define a isValid() function
  # With two arguments like hei and vel 
  # velocity and height repectively which is passed by 
  # isValid(hei, vel) fucntion 
    if(hei<=0):
      # here we are 
      # checking the condition
      # as hei which is height is <= 0
      # condition matches then
      # the below line is executed
      print("Please provide Height which should be a positive number.") 
    elif(vel<=0):
      # here we are 
      # checking the condition
      # as vel which is velocity is <= 0
      # condition matches then
      # the below line is executed
      print("Please provide Velocity which should be a positive number.") 
    else:
      # here we are 
      # executing this block
      # if none of the above two 
      # condition matches then
      # the below line is executed
      height = maximumHeight(hei,vel)
      # The above line called
      # maximumHeight fucntion 
      # with two parameter passsing and 
      # stored the result which 
      # is return by maximumHeight function 
      print("The maximum height of the ball is",height," feet.")
      # the above line display
      # the return the value by maximumHeight function
      time = approxTime(hei,vel) 
      # The above line called
      # the approxTime with
      # two parameters passing and 
      # stored the result on time which 
      # is return by the approxTime      
      print("The ball will hit the ground after approximately ",round(time,2)," seconds.")
      # the above line display which is 
      # the return the value by approxTime function
def maximumHeight(hei,vel):
  # This above line we 
  # define the maximumHeight function
  # with two arguments which is passed through
  # called function
  t = vel/32;
  # The above line we divide
  # velocity/32 to get the time  
  maxHeight = hei + (vel*t) - (16 * (t*t))
  # the above line
  # calulated the maxHeight
  # with the formula hei + (vel*t) - (16 * (t*t))
  return maxHeight 
  # this will return the value 
  # to the called fucntion
def approxTime(hei,vel):
  # here in the above line we
  # define the approxTime function with 
  # two arguments of
  # hei and vel height and velocity respectively
  t=0
  # the above line we initialize 
  # time with 0 as t = 0
  height=hei+(vel*t)-16*(t*t)
  # here in the above line
  # we calculate
  # height with the height formula as
  # hei+(vel*t)-16*(t*t) and stored in hei
  while height>=0:
    # the above loop we define
    # which executes
    # until condtion matched
    t+=.01
    # the above line 
    # we added the time(t) with time(t) 
    # and store in time (t)
    height=hei+(vel*t)-16*(t*t)
    # here we calculate
    # height as with
    # the formula height=hei+(vel*t)-16*(t*t)
    # stored the resutl in height
    # if height is >= 0
    # loop will break
  return t       
  #this line of code
  # will retrun the reuslt to the 
  # called function
getInput() 
# here in the above line we called the 
# getIbput() function

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY