Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: Python Program used: PyCharm Interpreter: 3.6.1 at ~/anaconda/bin/python Question 5 (3 points): Purpose: To practice console l/O, particularly reading numbers from the console, and

Language: Python

Program used: PyCharm

Interpreter: 3.6.1 at ~/anaconda/bin/python

image text in transcribed

Question 5 (3 points): Purpose: To practice console l/O, particularly reading numbers from the console, and use of variables. Degree of Difficulty: Easy We've all fantasized about destroying our computers when they don't work properly. In the spirit of sci entific inquiry. let's write a program to compute how long a computer will take to hit the ground when dropped out of a window. Ignoring air resistance, the time (in seconds) when the computer hits the ground is: t = VH/(0.5 9.8) In the above formula, t is the time in seconds, and H is the height in meters from which the computer is dropped with no initial velocity. The formula may not be accurate if you are throwing the computer! Write a Python program that does the following: (a) Put the following as the first line of your program: import math as m We'll cover this in class a bit later. For now, you can understand that this line allows us to use mathe- matical functions defined in the module called math. (b) Prompt the user to enter the starting height of the computer in meters. Read the user's response as a number using the input () syntax (see textbook Section 2.4.3 "Reading Numbers from the Keyboard") and set a variable called H to refer to it. (c) Compute the time at which the computer hits the ground using the above formula and have a vari- able called time of_impact refer to the result. You can compute the square root of the value of an expression by writing m.sqrt (expression). For example, the square root of two times seven can be written m.sqrt(2*7). This syntax is made available by the line you wrote in step (a): we're using the square-root function defined in the math module. (d) Use the values of the two variables to display a message to the console that describes the solution to the problem (see sample program run, below). Sample Run If you've completed your program correctly. you should see something like the following on the console when you run it: From what height is the computer dropped? 42 The computer dropped from 42.0 meters hits the ground after 2.9277002188455996 seconds, creating a satisfying explosion of circuitry! Note: the green number is text entered by the user at the console: blue text highlights the values referred to by program variables H andtime to_impact. Of course, you'll see different numbers if you enter different values of H. If you are using PyCharm, the input text will be green (unless you change the preferences), but none of Python's console output will be blue. What to Hand In Hand in your solution in a file called a1q5.py Evaluation 1 mark each for parts (b) through (d). The solution can be as short as three lines of code (not counting part (a)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions