Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

problem a Write a program (script) that calculates how far an object has fallen after a given time.Assume that it is stationary and that you

problem a

Write a program (script) that calculates how far an object has fallen after a given time.Assume that it is stationary and that you release it at time 0. The program should

a.Read a number from the user, which is the number of seconds the object has fallen.

b.Calculate the speed in meters per.second after the number of seconds with the formula speed = acceleration * time.The acceleration from gravity is 9.81 m / s2.

c.Calculate the distance the object has fallen in meters with the formula distance = 0.5 * speed * time

d.Print speed and distance.

answer:

GRAVITASJON = 9.81

fra_brukeren = input("Skriv inn antall sekunder objektet har falt: ") antall_sekunder = float(fra_brukeren) fart = GRAVITASJON*antall_sekunder distanse = 0.5*fart*antall_sekunder print(f"Etter {antall_sekunder} sekunder har objektet falt {distanse:.2f} og faller med fart {fart:.2f}")

problem b

Rewrite the program from problem a) so that it checks that the number the user has entered is a number greater than 0, and prints an error message if it is not greater than 0.

answer:

GRAVITASJON = 9.81

fra_brukeren = input("Skriv inn antall sekunder objektet har falt: ") antall_sekunder = float(fra_brukeren) if antall_sekunder >= 0.0: fart = GRAVITASJON*antall_sekunder distanse = 0.5*fart*antall_sekunder print(f"Etter {antall_sekunder} sekunder har objektet falt {distanse:.2f} og faller med fart {fart:.2f}") else: print("Antall sekunder kan ikke vre negativt!")

problem c

Extend the program from task b) to print speed and distance for more times.The program should ask the user for a time interval (for example, 2 seconds) and a number of intervals (for example, 10).Then the program should calculate speed and distance for each interval and print it out.In the example, the program should calculate and print speed and distance after 2, 4, 6, 8, 10, 12, 14, 16, 18 and 20 seconds.

answer:

GRAVITASJON = 9.81

brukerinput = input("Skriv inn intervallstrrelsen: ") intervallstorrelse = int(brukerinput) brukerinput = input("Skriv inn antall intervaller: ") antall_intervaller = int(brukerinput) if antall_intervaller >= 0.0 and intervallstorrelse > 0.0: for antall_sekunder in range(intervallstorrelse, intervallstorrelse*(antall_intervaller) + 1, intervallstorrelse): fart = GRAVITASJON*antall_sekunder distanse = 0.5*fart*antall_sekunder print(f"Etter {antall_sekunder} sekunder har objektet falt {distanse:.2f} " f"og faller med fart {fart:.2f}") else: print("Antall intervaller kan ikke vre negativt! Intervallstrrelse m vre " "positivt!")

problem d

Lists: rewrite the program in problem c) so that it plots the result in a graph with food plotlib instead of printing it to the console.You just need to plot the distance dropped as a function of time.This requires you to create two lists, a list of times and a list of distances.In the for-loop, enter values in the two lists.After the for-loop is complete, use the two lists when plotting.The times become the x-axis and the distances become the y-axis.

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago